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-08-02 15:03:28

    正则提取字段

    如下文案,如何提取中间的文案呢 eq: 我们的%%aaa%%不一致,哈哈哈 提取后是aaa

  • 2018-08-07 20:00:42

    xUtils3.0版本的发送同步网络请求的方式

    对于Android开发来说,基本都是用异步来从网络上请求数据,很少用到同步请求的。近日项目有个地方需要使用到同步请求(以我目前的知识储备来说好像只能用同步请求来解决这个问题了),去网上搜索相关资料,又没有找到什么明确的使用方法。所以记下来,以备不时之需。

  • 2018-08-14 23:35:28

    Retrofit 设置 超时时间

    今天开发的时候遇到一个网络请求超时的问题,后台处理是成功的,但是移动端返回的总是提示请求超时,在设置了retrofit请求超时的时间延长以后,就可以请求成功了,下面是配置的方法: