W
Wraithious
Guest
Hello, in my project I want to just copy a file in the included files without modifying or doing anything to it and save it in a folder.
So after realizing GMS' file handling functions do not work with .mp3 files I converted my file to an .ogg and I got it to load the file into a buffer and transfer it to a public folder through my extension, but the resulting file is not playable, the file is all there right down to the last byte, but always reports the track length is 00:00:00, same deal with .wav files, really weird, so I'm guessing maybe it's a problem with how I create the buffer? I'm not too good with buffers and alignments but my reasoning was if I made a u16 buffer with a 1 alignment it would just copy the file byte for byte and not change anything, but I'm guessing the meta data somehow gets lost (doubtful because every single byte is accounted for) or that maybe I have to use an alignment of 2 or 4 to account for mono or stereo but I really have no idea? Can anyone help with this? here is my code on the GMS side:
and if it helps, here is my code in my extension that extracts the buffer data to an android public folder:
So after realizing GMS' file handling functions do not work with .mp3 files I converted my file to an .ogg and I got it to load the file into a buffer and transfer it to a public folder through my extension, but the resulting file is not playable, the file is all there right down to the last byte, but always reports the track length is 00:00:00, same deal with .wav files, really weird, so I'm guessing maybe it's a problem with how I create the buffer? I'm not too good with buffers and alignments but my reasoning was if I made a u16 buffer with a 1 alignment it would just copy the file byte for byte and not change anything, but I'm guessing the meta data somehow gets lost (doubtful because every single byte is accounted for) or that maybe I have to use an alignment of 2 or 4 to account for mono or stereo but I really have no idea? Can anyone help with this? here is my code on the GMS side:
Code:
fname = "wildDubz.ogg";
if(file_exists(fname))
{file = file_bin_open(fname,0);
size = file_bin_size(file);
gameTransfer = buffer_create(1024, buffer_grow, 1);
for(var i=0;i<size;i+=1;){buffer_write(gameTransfer,buffer_s16,file_bin_seek(file,i));}
var buffaddress = buffer_get_address(gameTransfer);
SaveFromAs(buffaddress,global.myFolder,"wildDubz.ogg",size);
file_bin_close(file);}
if !file_exists(fname) show_debug_message("file_open_bin has failed to open the file");
Code:
//buffer address, absolute path to output folder, new file name, file size in bytes
public void SaveFromAs(String inputPath, String opp, String opn, double setToRing) {
int numOfBytes = (int)setToRing;
Log.i("yoyo", "295: Buffer size: " + String.valueOf(numOfBytes));
try
{
mf = new MemoryFile(inputPath, numOfBytes);
InputStream in = null;
OutputStream out = null;
in = mf.getInputStream();
Log.i("yoyo", "302: Found the file, input stream created: " + String.valueOf(in));
out = new FileOutputStream(opp + "/" + opn);Log.i("yoyo", "303: Output stream created");
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
OsUpdt(opp + "/" + opn);
ReturnGMS("buff","buff_finished","","",-4,-4);
}
catch(IOException e)
{
Log.i("yoyo", "315: Couldn't find file");
Log.e("tag", "Failed to copy asset file: " + inputPath, e);
}
}
private void copyFile(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[1024];
int read;
while((read = in.read(buffer)) != -1)
{
out.write(buffer, 0, read);
}
}