InnerAudioContext真机播放报错
wx.createInnerAudioContext 创建组件进行音频播放,在开发工具中没有任何问题,换到手机上就报错,帮忙看看是啥问题呢,谢谢。
大概的代码如下,url会把传入的信息转成wav音频。
play: function (e) { //const audio = wx.createInnerAudioContext(); if (!audio.paused) { audio.stop(); } if ( this .data.src.length == '' ) { this .translate(); } audio.autoplay = true ; audio.src = app.globalData.apiUrl + "?cw=" + encodeURIComponent(base64.encode( this .data.src)); console.log(audio.src); audio.onPlay(() => { console.log( 'onPlay:开始播放' ); this .setData({ isplaying: true , playcss: 'selected' , pausecss: '' }); }); audio.onPause(() => { console.log( 'onPause:音频暂停事件' ); this .setData({ playcss: '' , pausecss: 'selected' }); curTime = audio.currentTime; }); audio.onTimeUpdate(() => { console.log( 'onTimeUpdate:音频播放进度更新事件' ); console.log(audio.currentTime); }); audio.onEnded(() => { console.log( 'onEnded:音频自然播放结束事件' ); this .setData({ isplaying: false , playcss: '' , pausecss: '' }); curTime = 0; }); audio.onStop(() => { console.log( 'onStop:音频停止事件' ); this .setData({ isplaying: false , playcss: '' , pausecss: '' }); curTime = 0; //audio.destroy(); }); audio.onError((res) => { console.log( "onError:" + res.errMsg); console.log(res); //audio.destroy(); }); audio.onWaiting((res) => { console.log( 'onWaiting:音频加载中事件,当音频因为数据不足,需要停下来加载时会触发' ) console.log(res) }); audio.onCanplay(() => { console.log( 'onCanplay' ); audio.play(); }); |
4 回复
哎,只能在服务端把wav转成mp3了。希望官方尽快给出好的解决访问或者在文档增加详细的说明,到底哪些文件在那些系统可以使用吧。这个问题应该只有IOS才会出现。。。。
下面是服务端将wav转成mp3的代码,需要的可以参考
$wavfile = $_REQUEST [ 'wav' ]; $wav = file_get_contents ( $wavfile ); $descriptorspec = array ( 0 => array ( "pipe" , "r" ), 1 => array ( "pipe" , "w" ), 2 => array ( "file" , "/dev/null" , "w" ) ); $process = proc_open( "/usr/bin/lame - -" , $descriptorspec , $pipes ); fwrite( $pipes [0], $wav ); fclose( $pipes [0] ); $mp3 = stream_get_contents( $pipes [1] ); fclose( $pipes [1] ); proc_close( $process ); header( 'Content-Type: audio/mpeg' ); echo $mp3 ; |
这个是github上的一个类库,原理相同