File tree Expand file tree Collapse file tree 2 files changed +31
-5
lines changed Expand file tree Collapse file tree 2 files changed +31
-5
lines changed Original file line number Diff line number Diff line change 3333 </ style >
3434</ head >
3535< body >
36- < audio id ="audio " src =" ">
36+ < audio id ="audio " autoplay =" autoplay ">
3737 </ audio >
3838 < div id ="chat "> </ div >
3939 < script src ="/public/vue/vue.js "> </ script >
4646 //var receiver_socket = new WebSocket("wss://"+document.domain+":9503");
4747 var image = document . getElementById ( 'receiver' ) ;
4848 var audio = document . querySelector ( 'audio' ) ;
49+ window . initPlayer = function ( obj ) {
50+ obj . playlist = [ ] ; //播放列表
51+ obj . position = 0 ; //当前播放位置
52+ //播放音乐(循环播放)
53+ obj . start = function ( ) {
54+ if ( jQuery . isArray ( obj . playlist ) && obj . playlist . length >= 1 ) {
55+ $ ( obj ) . attr ( "src" , obj . playlist [ obj . position % obj . playlist . length ] ) ;
56+ obj . play ( ) ;
57+ }
58+ } ;
59+ //播放一个列表
60+ obj . playList = function ( arr ) {
61+ if ( jQuery . isArray ( arr ) && arr . length >= 1 ) {
62+ obj . playlist = arr ;
63+ obj . position = 0 ;
64+ obj . start ( ) ;
65+ }
66+ } ;
67+ //播放下一首
68+ $ ( obj ) . on ( "ended" , function ( e ) {
69+ obj . playlist . shift ( ) ;
70+ //obj.position++;
71+ obj . start ( ) ;
72+ } ) ;
73+ } ;
74+ initPlayer ( audio ) ;
4975 receiver_socket . onmessage = function ( data )
5076 {
5177 zqfdata = jQuery . parseJSON ( data . data ) ;
6086 //console.log(zqfdata.data);
6187 //console.log(window.URL.createObjectURL(blob));
6288 //$('#audio').attr('src',zqfdata.data);
63-
64- audio . src = zqfdata . data ;
89+ audio . playlist . push ( zqfdata . data ) ;
90+ // audio.src =zqfdata.data;
6591 if ( audio . paused ) {
66- audio . play ( ) ;
92+ audio . start ( ) ;
6793 }
6894 /*g_audio.elems["id"] = '';
6995 g_audio.push({
Original file line number Diff line number Diff line change 9292 //压缩
9393 var compression = parseInt ( this . inputSampleRate / this . outputSampleRate ) ;
9494 var length = data . length / compression ;
95- console . log ( length ) ;
95+ // console.log(length);
9696 var result = new Float32Array ( parseInt ( length ) ) ;
9797 var index = 0 , j = 0 ;
9898 while ( index < length ) {
You can’t perform that action at this time.
0 commit comments