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

    }

}


  • 2020-12-18 17:26:25

    coturn配置文件详细解释

    Coturn 是webrtc,p2p视频通话必不少的,主要包含2个主要功能stun服务, turn服务 Coturn 的githup地址为 https://github.com/coturn/coturn/

  • 2020-12-21 06:26:16

    为UIView添加点击事件

    最近经常碰到要将UIImageView和UILabel看成整体的情况,我于是就将他俩用UIView包起来,那么怎么给一个UIView添加点击事件,可以这么实现:

  • 2020-12-21 09:00:20

    Window.matchMedia() 方法详解

    matchMedia() 返回一个新的 MediaQueryList 对象,表示指定的媒体查询字符串解析后的结果。 matchMedia() 方法的值可以是任何一个 CSS @media 规则 的特性, 如 min-height, min-width, orientation 等。 MediaQueryList 对象有以下两个属性:

  • 2020-12-21 09:42:42

    iframe.contentWindow 操作iframe

    注:iframe.contentWindow这里,返回的是iframe的window对象,所以后面可以接着调用document方法,再接着调用getElementByTagName。那么就可以对iframe里面的元素进行操作了。

  • 2020-12-21 14:00:19

    iframe + postMessage跨域通信

    在实际项目开发中可能会碰到在 a.com 页面中嵌套 b.com 页面,这时第一反应是使用 iframe,但是产品又提出在 a.com 中操作,b.com 中进行显示,或者相反。

  • 2020-12-22 12:02:41

    ios开发优秀的开源框架,demo集合

    期待大家和我们一起共同维护,同时也期望大家随时能提出宝贵的意见(直接提交issues即可)。请广大网友只按照目录结构(即使目录结构有问题)添加三方库,并提交pull request。目录问题大家提出issues后楼主会及时更改的。