开发者

how to play audio using audiotrack in android

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜