开发者

how to play audio using audiotrack in android

开发者 https://www.devze.com 2023-04-05 04:40 出处:网络
I\'m developing an android app that will play mp3 files. However the mp3 files are encrypted on the sd card . Either ways, after decryption, i\'ll have a stream 开发者_StackOverflow中文版of bytes. I h

I'm developing an android app that will play mp3 files. However the mp3 files are encrypted on the sd card . Either ways, after decryption, i'll have a stream 开发者_StackOverflow中文版of bytes. I hav used audio track class but unable to play the audio.plz help me. thank you in advance.


You could save the stream to a temporary (mp3) file and then play this file with MediaPlayer

EDIT to address comment:
The file would not be persistent, something like

File temp = File.createTempFile("whatever", "mp3", getCacheDir());
temp.deleteOnExit();
FileOutputStream fStream = new FileOutputStream(temp);
fStream.write(passYourStream);
fStream.close(); 
FileInputStream fStream2 = new FileInputStream(temp);
yourMediaPlayerInstance.setDataSource(fStream2.getFD());


Hi i think it is useful to you http://www.bogotobogo.com/Android/android24MediaB.html#AudioPlay

0

精彩评论

暂无评论...
验证码 换一张
取 消