I have byte[] array, which contains mp3 file. Is there any way how to play mp3 file without creating temporary file?
Thanks
Edited:
I have tried temporary file approach:
File tempMp3 = File.createTempFile("test", ".mp3", getCacheDir());
//tempMp3.deleteOnExit();
FileOutputStream fos = new FileOutputStream(tempMp3);
fos.write(bytes);
fos.close();
mediaPlayer = MediaPlayer.create(getApplicationContext(),Uri.fromFile(tempMp3));
mediaPlayer.start();
And I am still getting the NullPointerException. I am writing byte array (called bytes) to file, I am keeping its referrence and using it. But still getting NPE. Do you know where is the mistake?
I am assuming you are using MediaPlayer
and until the latest API there is no way to set the data in byte[]
format just as a String
(path), FileDescriptor
, or Uri
so I am afraid that you will have to write a temporary File
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With