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

2021-01-06 23:04:11


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();

    }

}


  • 2018-03-13 22:42:44

    TraceView报错:unable to open trace file

    程序效率有些问题,想起用TraceView来分析一下,可是一直报标题中的错误,无法创建出我所需要的aa.trace文件,分析也就无从做起。

  • 2018-03-14 17:41:44

    MySQL的if,case语句使用总结

    Mysql的if既可以作为表达式用,也可在存储过程中作为流程控制语句使用,如下是做为表达式使用:

  • 2018-03-16 23:56:14

    layer-list -- layer-list的基本使用介绍

    简单理解,layer 是层,list 是列表,那么 layer-list 就是层列表的意思。但是,是什么层列表呢?? 其实 layer-list 是用来创建 LayerDrawable 的,LayerDrawable 是 DrawableResource 的一种, 所以,layer-list 创建出来的是 图层列表,也就是一个drawable 图形。