当前位置: 代码迷 >> Android >> android从byte[]字节数组中播发mp3音乐
  详细解决方案

android从byte[]字节数组中播发mp3音乐

热度:94   发布时间:2016-05-01 15:22:36.0
android从byte[]字节数组中播放mp3音乐
private void playMp3(byte[] mp3SoundByteArray) {    try {        // create temp file that will hold byte array        File tempMp3 = File.createTempFile("kurchina", "mp3", getCacheDir());        tempMp3.deleteOnExit();        FileOutputStream fos = new FileOutputStream(tempMp3);        fos.write(mp3SoundByteArray);        fos.close();        // Tried reusing instance of media player        // but that resulted in system crashes...          MediaPlayer mediaPlayer = new MediaPlayer();        // Tried passing path directly, but kept getting         // "Prepare failed.: status=0x1"        // so using file descriptor instead        FileInputStream fis = new FileInputStream(tempMp3);        mediaPlayer.setDataSource(fis.getFD());        mediaPlayer.prepare();        mediaPlayer.start();    } catch (IOException ex) {        String s = ex.toString();        ex.printStackTrace();    }}

?http://blog.pocketjourney.com/2009/12/27/android-streaming-mediaplayer-tutorial-updated-to-v1-5-cupcake/

上面也是一个不错的博客

也是关于音乐下载问题

1 楼 jiyuan18 2012-05-09  
  相关解决方案