MusicShareApeTwo.js
24.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
//*
// 伴音共享模块
// */
import Loger from "../Loger";
import Ape from "./Ape";
import xdysdk from "libs/xdysdk";
import $ from "jquery";
import ClassDataProxy from "proxy/ClassDataProxy";
import FlashToolComponet from "libs/FlashToolComponet";
import HLSPlayer from 'tinyhls';
import MD5 from "md5";
import UIControlApe from './UIControlApe';
import ErrorApe from './ErrorApe';
import MusicControlBarApe from './MusicControlBarApe';
let loger = Loger.getLoger('PC-MusicShareApeTwo');
let fileItem;
class MusicShareApeTwo extends Ape {
constructor() {
super();
this.h5MusicPlayer = null;//HLS播放
this.currPlayMusicId = 0;//当前选择的文件
this.musicShareFileList = {};//伴音数据列表
this.controlBar = new MusicControlBarApe();
this.controlBar.controlCallback = this._controlCallback.bind(this);
this.addEvent();
this._hideMusicShareBox();
}
init() {
//UI按钮点击事件
$("#musicFileBtn").on("change", this._uploadFile.bind(this));//上传文件
$("#musicUploadOut").on("click", this._openListHandler.bind(this));//打开列表
$("#closeMusicList").on("click", this._closeListHandler.bind(this));//关闭列表
}
addEvent() {
xdysdk.on("class_get_info_success", this._classGetInfoSuccessHandler.bind(this));//课堂数据获取成功之后就可以创建伴音共享的flash或H5播放器
xdysdk.on("music_stop_publish", this._musicStopPublishHandler.bind(this));
xdysdk.on("class_join_success", this._classJoinSuccessHandler.bind(this));
xdysdk.on("music_shared_update", this._onMusicShareUpdateHanlder.bind(this));//伴音更新
xdysdk.on("music_shared_delete", this._onMusicShareDeleteHanlder.bind(this));//伴音删除
}
creatHLSPlayer() {
loger.log('伴音共享录制回放->创建h5播放器');
//创建h5播放器
$('.h5MusicBox').show();
let audio = document.getElementById('h5Music');
this.h5MusicPlayer = new HLSPlayer(audio);
this.h5MusicPlayer.divName = 'h5Music';
this.h5MusicPlayer.isMobile = true;//按移动端播放处理,使用原生的audio
this.h5MusicPlayer.status = MusicShareApeTwo.STOP;
$("#h5Music")[0].poster = "";//不需要背景图片
//给控制条绑定audio
this.controlBar.audio = audio;
}
//事件监听-----------
_classGetInfoSuccessHandler(_data) {
this.init();
this.creatHLSPlayer()
}
//停止当前的所有伴音共享
_musicStopPublishHandler() {
if (ClassDataProxy.userRole == ClassDataProxy.USER_HOST) {
loger.log('停止当前的所有伴音共享->');
if (this.currPlayMusicId > 0) {
this._stopMeidaShare(this.currPlayMusicId);
}
}
}
//监听控制条消息
_controlCallback(_callBackData) {
if (ClassDataProxy.userRole != ClassDataProxy.USER_HOST || ClassDataProxy.isRecordPlayBack) {
loger.log("伴音共享播放器监听控制->录制回放和不是老师不处理");
return;
}
loger.log("伴音共享播放器监听控制->", _callBackData);
if (_callBackData) {
//{"action":"pause","data":{"seek":36.027015,"musicVolume":60}}
switch (_callBackData.action) {
case MusicControlBarApe.STOP:
if (this.h5MusicPlayer && this.h5MusicPlayer.musicId > 0) {
this._updateMeidaShare(this.h5MusicPlayer.musicId, 0, _callBackData.data.seek, _callBackData.data.musicVolume);
}
break;
case MusicControlBarApe.PLAY:
//loger.log("当前状态是什么===", _callBackData);
if (this.h5MusicPlayer && this.h5MusicPlayer.musicId > 0) {
this._updateMeidaShare(this.h5MusicPlayer.musicId, 1, _callBackData.data.seek, _callBackData.data.musicVolume);
}
break;
case MusicControlBarApe.PAUSE:
if (this.h5MusicPlayer && this.h5MusicPlayer.musicId > 0) {
this._updateMeidaShare(this.h5MusicPlayer.musicId, 2, _callBackData.data.seek, _callBackData.data.musicVolume);
}
break;
default:
break;
}
}
}
_classJoinSuccessHandler(_data) {
if (_data.userRole == ClassDataProxy.USER_HOST && !ClassDataProxy.isRecordPlayBack) {
//如果是老师端,需要开启定时同步数据的状态
if (this.controlBar) {
this.controlBar.isOpenUpdateStatusInfo = true;
}
$("#musicShareBoxMask").hide();
} else {
$("#musicUpLoadOut").hide();//上传按钮的父级div
$("#musicFile").hide();
$("#musicListOut").hide();
//伴音共享区域的遮罩层,身份不是老师的时候就显示
$("#musicShareBoxMask").show();
}
}
//监听伴音更新消息
_onMusicShareUpdateHanlder(_data) {
loger.log("伴音模块收到SDK数据", _data);
if (_data == null) {
return;
}
this._updateListData(_data, "add");
switch (_data.status) {
case 0:
//停止
loger.log("停止伴音");
this._tryStopMusicHandler(_data.itemIdx);
break;
case 1:
//播放
loger.log("播放伴音");
this._playMusicHandler(_data.itemIdx);
break;
case 2:
//暂停
loger.log("暂停伴音");
this._tryPauseMusicHandler(_data);
break;
case 4:
//暂停
loger.log("静音");
this._offMusicHandler(_data);
break;
default:
break;
}
}
//监听伴音删除消息
_onMusicShareDeleteHanlder(_data) {
loger.log("_onMusicShareDeleteHanlder", _data);
this._updateListData(_data, "delete");
}
//更新伴音数据(包括更新和删除) _type='add' 添加
_updateListData(_data, _type) {
if (_type == "add" && _data) {
//loger.log("添加文件数据", _data);
this.musicShareFileList[_data.itemIdx] = _data;
} else {
loger.log("删除伴音数据", _data.itemIdx);
delete this.musicShareFileList[_data.itemIdx];
if (this.h5MusicPlayer && this.h5MusicPlayer.musicId == _data.itemIdx) {
UIControlApe.enabledBottomBar();
UIControlApe.enabledLeftBar();
UIControlApe.showBottomDocControlBar();
this.currPlayMusicId = 0;
this.h5MusicPlayer.rtmpURL = '';
this.h5MusicPlayer.musicId = 0;
this.h5MusicPlayer.nodeId = 0;
this.h5MusicPlayer.status = MusicShareApeTwo.STOP;
this.h5MusicPlayer.stop();
this.h5MusicPlayer.pause();
$("#h5Music").attr("src", "");
this.controlBar.stop();
this._hideMusicShareBox();
}
}
//更新文件列表
this._updateDocListView();
}
//更新文件列表显示
_updateDocListView() {
$("#musicFileContent").empty();
// loger.log("this.musicList", this.musicShareFileList);
for (let i in this.musicShareFileList) {
if (this.musicShareFileList[i].fileId) {
let listItem = this._creatListItemDiv(i, this.musicShareFileList[i].fileName, this.musicShareFileList[i].itemIdx);
$("#musicFileContent").append(listItem);//添加到伴音列表中
}
}
}
//显示伴音区域
_showMusicShareBox(_data) {
// loger.log('显示伴音区域');
$("#musicShareGroup").show();
//$("#musicShareGroup").css("z-index", 4);
//显示之后需要更新布局
}
//隐藏伴音区域
_hideMusicShareBox(_data) {
//loger.log('隐藏伴音区域');
$("#musicShareGroup").hide();
//$("#musicShareGroup").css("z-index", -7);
}
//停止并且隐藏
stopAndHide() {
loger.log("伴音模块-停止并且隐藏-.stopAndHide")
this._stopMeidaShare(this.currPlayMusicId);
if (this.controlBar) {
this.controlBar.stop();
}
this.currPlayMusicId = 0;
this._hideMusicShareBox();
this._closeListHandler();
}
//显示伴音列表
_openListHandler() {
this._emit(MusicShareApeTwo.SCENE_MUSIC_SHARE_CHANGE, ClassDataProxy.SCENE_MUSIC_SHARE);
$("#musicShareModal").show();
$(".masker").show();
}
//关闭伴音列表
_closeListHandler() {
$("#musicShareModal").hide();
$(".masker").hide();
}
//上传文件
_uploadFile(evt) {
fileItem = document.getElementById('musicFileBtn').files[0];
if (!fileItem) {
loger.log("没有选择文件");
return;
}
this._closeListHandler();
loger.log("fileItem.type=====", fileItem);
let fileStr = fileItem.name;
let fileValue = fileStr.split('.')[1];
loger.log("文件名:" + fileItem.name + "->文件类型:" + fileItem.type);
//目前最大支持50M 格式为jpg png pdf docx pptx xlsx
//判断文件的大小
if (fileItem.size > (100 * 1024 * 1024)) {
ErrorApe.showError(ErrorApe.TYPE_3,ClassDataProxy.localConfig.fileError);
return;
}
let fileName = fileItem.name.toLowerCase();
//判断选择的文件类型
if (fileName.lastIndexOf('.mp3') < 0) {
ErrorApe.showError(ErrorApe.TYPE_3,ClassDataProxy.localConfig.musicLayoutCont);
return;
}
if (!ClassDataProxy.DOCServerIP) {
loger.warn("伴音服务器地址无效,无法上传文件!");
ErrorApe.showError(ErrorApe.TYPE_3,ClassDataProxy.localConfig.serverError);
return
}
//上传时动画效果
UIControlApe.showLoadingMask();
UIControlApe.disEnabledDocBar();
UIControlApe.disEnabledMusicBar();
let timestamp = ClassDataProxy.creatTimestamp();
let authId = MD5(ClassDataProxy.siteId + "" + timestamp);///authId String MD5(siteId+timestamp)
let fd = new FormData();
fd.append("fileToUpload", fileItem);
fd.append("filename", escape(fileItem.name));
fd.append("size", fileItem.size);
fd.append("siteId", ClassDataProxy.siteId); //站点
fd.append("createUserName", String(ClassDataProxy.userName)); //上传人姓名
fd.append("createUserID", String(ClassDataProxy.nodeId)); //上传人ID
fd.append("timestamp", String(timestamp)); //时间戳
fd.append("authId", authId); //上传时间
fd.append("classId", String(ClassDataProxy.classId)); //课堂号
/* let ipport = ClassDataProxy.DOCServerIP;
if (ClassDataProxy.DOCServerPort) {
ipport = ipport + ":" + ClassDataProxy.DOCServerPort;
}
let musicUploadUrl = `http://${ipport}/DocSharing/mediaupload`;*/
let ipport=ClassDataProxy.DOCServerIP;
if( ClassDataProxy.DOCServerPort){
ipport=ipport+":"+ClassDataProxy.DOCServerPort;
}
let musicUploadUrl= `${ClassDataProxy.locationProtocol+ipport}/DocSharing/mediaupload`;
$.ajax({
type: "POST",
url: musicUploadUrl,
processData: false,
contentType: false,
data: fd,
xhr: function () {
let xhr = $.ajaxSettings.xhr();
if (xhr.upload) {
xhr.upload.addEventListener("progress", function (evt) {
let loaded = evt.loaded; //已经上传大小情况
let tot = evt.total; //附件总大小
let per = Math.floor(100 * loaded / tot); //已经上传的百分比
UIControlApe.updataLoadingMaskProgress(per);
}, false);
return xhr;
}
},
success: function (data) {
//loger.log("伴音服务器返回的伴音数据-.", data);
UIControlApe.hideLoadingMask();
UIControlApe.enabledDocBar();
UIControlApe.enabledMusicBar();
//UIControlApe.enabledLeftBar();
//UIControlApe.enabledBottomBar();
//UIControlApe.showBottomDocControlBar();
this._uploadFileSuccess(data);
$("#musicFileBtn").val('');
}.bind(this),
error: function (data) {
//UIControlApe.enabledLeftBar();
//UIControlApe.enabledBottomBar();
//UIControlApe.showBottomDocControlBar();
UIControlApe.hideLoadingMask();
UIControlApe.enabledDocBar();
UIControlApe.enabledMusicBar();
loger.warn(name + "->上传文件失败", data);
ErrorApe.showError(ErrorApe.TYPE_3,name + "->" + ClassDataProxy.localConfig.uploaDocumentErr);
$("#musicFileBtn").val('')
}
});
}
//将上传文件的信息,传递给底层
_uploadFileSuccess(msg) {
loger.log("服务器返回的伴音信息->", msg);
//{"code":0,"list":[{"name":"sintel (2).mp4","id":"7","url":"http://101.200.150.192:9090/media/h5dev/201706/1478111117/76303834c69cd86f6c6212ae3019b1d0.mp4"}]}
/*
//code
0:成功
1:不是上传请求
2:编码错误
3:无法解析请求内容
4:没有上传文件,或者上传文件超过10个
5:siteId 不能为空
6:authId 错误
7:文件类型不支持
8:保存文件信息失败
10:保存文件失败*/
if (msg && msg.code == 0) {
//返回的数据中是一个数组,支持多个上传,目前只处理一个上传的情况
if (!msg.list || msg.list.length < 1) {
loger.warn('上传文件返回的数据中数组没有数据', msg.list);
return;
}
let item = msg.list[0];
if (item && item.id) {
//{"name":"sintel (2).mp4","id":"7","url":"http://101.200.150.192:9090/media/h5dev/201706/1478111117/76303834c69cd86f6c6212ae3019b1d0.mp4"}
let fileInfo = {};
fileInfo.fileId = item.id; //伴音在数据库中的唯一id标识 默认值: null
fileInfo.fileName = fileItem.name;//伴音名字
fileInfo.url = item.url; //伴音绝对地址 默认值: null
fileInfo.duration = parseInt(item.duration) || 0;
xdysdk.api("musicSharedUpload", fileInfo);
} else {
loger.warn("服务器返回的文件信息->不能同步-->id无效", msg.id);
ErrorApe.showError(ErrorApe.TYPE_3,ClassDataProxy.localConfig.uploaDocumentErr);
}
} else {
loger.warn("音频上传失败->", msg.code);
ErrorApe.showError(ErrorApe.TYPE_3,'音频上传失败->code:' + msg.code);
}
}
//点击列表中切换伴音
_clickListToSwitchBtnHandler(evt) {
let _itemIdx = parseInt(evt.target.id);
let listItem = this.musicShareFileList[_itemIdx];
//切换视频之前先停止之前播放的文件
this._stopMeidaShare(this.currPlayMusicId);
this.currPlayMusicId = 0;
loger.log('点击列表中切换伴音->播放列表中的伴音文件->', listItem);
this._playMeidaShare(listItem.itemIdx);
this._closeListHandler();//隐藏列表
if (ClassDataProxy.userRole != ClassDataProxy.USER_HOST) {
this._hideMusicShareBox();
}
}
//切换伴音,把要显示的伴音数据发送给SDK
_playMusicHandler(_itemIdx) {
let listItem = this.musicShareFileList[_itemIdx];
if (listItem) {
if (ClassDataProxy.userRole == ClassDataProxy.USER_HOST) {
this._showMusicShareBox();
}
loger.log("_playMusicHandler", listItem);
////录制回放使用H5播放
if (this.h5MusicPlayer) {
loger.log(ClassDataProxy.currentSceneTableId, ClassDataProxy.SCENE_DOC);
if (ClassDataProxy.currentSceneTableId != ClassDataProxy.SCENE_DOC) {
//录制回放的时候,如果收到播放的消息,但是当前没有切换到伴音模块,那么就停止播放
loger.log('_playMusicHandler录制回放->但是当前没有切换到伴音模块->currentSceneTableId->' + ClassDataProxy.currentSceneTableId);
this._tryStopMusicHandler(listItem.itemIdx);
return;
}
this.currPlayMusicId = listItem.itemIdx;
//回放的时候只播放状态为1的,2暂停的不播放
if (listItem.status == 1) {
let seek = listItem.seek || 1;
loger.log('收到伴音共享播放->seek->' + seek);
//-----------------------------判断是否同步处理---------------------------------------------------
//如果媒体已经在播放,并且是同一个文件,那么判断收到的消息中seek和当前的seek差值;
if (this.h5MusicPlayer.status == MusicShareApeTwo.PLAY&&
this.h5MusicPlayer.rtmpURL==listItem.url) {
let seekDistance=Math.abs(seek-this.controlBar.seekTime);
let volumeDistance=Math.abs(this.controlBar.musicVolume-listItem.musicVolume);
loger.warn('当前正在播放->seekTime:' + this.controlBar.seekTime,"seek:"+seek,"seekDistance:"+seekDistance);
loger.warn('当前正在播放->当前音量:' + this.controlBar.musicVolume,"新的音量值:"+listItem.musicVolume);
//如果两次的差值小于相差小于3秒并且音量值未发生改变
if(seekDistance<3&&volumeDistance==0){
loger.warn("不需要seek");
return;
}else {
this.h5MusicPlayer.seek(seek);
this.h5MusicPlayer.status = MusicShareApeTwo.PLAY;
this.controlBar.seek(seek);
this.controlBar.changeVolume(listItem.musicVolume);
return;
}
}
//-----------------------------判断是否同步处理-END-------------------------------------------------------
this.h5MusicPlayer.rtmpURL = listItem.url;
this.h5MusicPlayer.nodeId = listItem.fromNodeId;
this.h5MusicPlayer.musicId = listItem.itemIdx;
this.h5MusicPlayer.play(listItem.url, HLSPlayer.MODE_VOD, seek);
this.h5MusicPlayer.status = MusicShareApeTwo.PLAY;
this.h5MusicPlayer.seek(seek);
this.controlBar.play(seek);
this.controlBar.changeVolume(listItem.musicVolume);
$(".musicShareName").html(listItem.fileName);//显示音乐的名字
}
}
}
}
//暂停
_tryPauseMusicHandler(_data) {
if (!_data) {
return;
}
loger.log("_tryPauseMusicHandler", _data)
let listItem = this.musicShareFileList[_data.itemIdx];
if (listItem) {
// loger.log('播放列表中的伴音文件->',listItem);
if (ClassDataProxy.userRole == ClassDataProxy.USER_HOST) {
this._showMusicShareBox();
}
////录制回放使用H5播放
if (this.h5MusicPlayer) {
if (ClassDataProxy.currentSceneTableId != ClassDataProxy.SCENE_DOC) {
//录制回放的时候,如果收到播放的消息,但是当前没有切换到伴音模块,那么就停止播放
loger.log('_tryPauseMusicHandler录制回放->但是当前没有切换到伴音模块->currentSceneTableId->' + ClassDataProxy.currentSceneTableId);
this._tryStopMusicHandler(listItem.itemIdx);
return;
}
this.currPlayMusicId = listItem.itemIdx;
//暂停
if (listItem.status == 2) {
let seek = listItem.seek || 1;
loger.log('录制回放->收到伴音共享播放->seek->' + seek);
this.h5MusicPlayer.rtmpURL = listItem.url;
this.h5MusicPlayer.nodeId = listItem.fromNodeId;
this.h5MusicPlayer.musicId = listItem.itemIdx;
this.h5MusicPlayer.play(listItem.url, HLSPlayer.MODE_VOD, seek);
this.h5MusicPlayer.pause();
this.h5MusicPlayer.status = MusicShareApeTwo.PAUSE;
this.controlBar.pause();
this.controlBar.changeVolume(listItem.musicVolume);
}
}
}
}
//静音
_offMusicHandler(_data) {
if (!_data) {
return;
}
loger.log("_offMusicHandler", _data)
document.getElementById("h5Music").volume = 0;
}
//伴音数据有更新,尝试停止
_tryStopMusicHandler(_itemIdx) {
loger.log("伴音数据有更新,尝试停止====")
if (this.h5MusicPlayer && this.h5MusicPlayer.musicId == _itemIdx) {
this.currPlayMusicId = 0;
this.h5MusicPlayer.rtmpURL = '';
this.h5MusicPlayer.musicId = 0;
this.h5MusicPlayer.nodeId = 0;
this.h5MusicPlayer.pause();
this.h5MusicPlayer.status = MusicShareApeTwo.STOP;
$("#h5Music").attr("src", "");
this.controlBar.stop();
this._hideMusicShareBox();
}
}
//删除伴音鼠标事件
_deleteDcoHandler(evt) {
loger.log("删除伴音鼠标事件->", evt.target.id);
let listItem = this.musicShareFileList[parseInt(evt.target.id)];
if (listItem) {
let paramInfo = {
"itemIdx": listItem.itemIdx,
"fileId": listItem.fileId,
"classId": ClassDataProxy.classId //课堂号
};
xdysdk.api("musicSharedDelete", paramInfo);
} else {
loger.log("删除伴音鼠标事件---->伴音不存在");
}
}
//调用SDK停止伴音共享播放
_stopMeidaShare(_itemIdx) {
loger.log('调用SDK停止伴音共享->', itemIdx);
let itemIdx = parseInt(_itemIdx);
if (itemIdx > 0) {
let result = xdysdk.api("musicSharedStop", {itemIdx: parseInt(itemIdx), status: 0});
}
}
_playMeidaShare(_itemIdx) {
loger.log('调用SDK开始伴音共享');
let itemIdx = parseInt(_itemIdx);
if (itemIdx > 0) {
let result = xdysdk.api("musicSharedPlay", {
itemIdx: parseInt(_itemIdx),
status: 1,
seek: 1,
musicVolume: 30
});
}
}
//更新伴音的状态
_updateMeidaShare(_itemIdx, _status, _seek, _musicVolume) {
loger.log('调用SDK -更新伴音共享状态->', _itemIdx, _status, _seek, _musicVolume);
if (ClassDataProxy.userRole == ClassDataProxy.USER_HOST && !ClassDataProxy.isRecordPlayBack) {
let result = xdysdk.api("musicSharedUpdate", {
itemIdx: parseInt(_itemIdx),
status: parseInt(_status),
seek: parseInt(_seek),
musicVolume: parseInt(_musicVolume)
});
}
}
//创建列表元素
_creatListItemDiv(_id, _fileName, _owner) {
let div = document.createElement("div");
div.id = "doc_" + _id;
//文件id
let ico = document.createElement("label");
ico.innerHTML = "";
ico.className = "iconfont";
div.appendChild(ico);
//文件名称
let nameDiv = document.createElement("label");
nameDiv.innerText = "" + _fileName;
nameDiv.title = "" + _fileName;
nameDiv.onclick = this._clickListToSwitchBtnHandler.bind(this);
nameDiv.id = _id;
div.appendChild(nameDiv);
//删除按钮
let deleteBtn = document.createElement("label");
deleteBtn.type = "button";
// deleteBtn.value = "删除";
deleteBtn.id = _id;
deleteBtn.innerHTML = "";
deleteBtn.className = "iconfont";
deleteBtn.onclick = this._deleteDcoHandler.bind(this);
div.appendChild(deleteBtn);
return div;
}
clear() {
loger.log("clear");
this.musicShareFileList = {};//伴音数据
this._hideMusicShareBox();
try {
if (this.h5MusicPlayer) {
this.h5MusicPlayer.rtmpURL = '';
this.h5MusicPlayer.musicId = 0;
this.h5MusicPlayer.nodeId = 0;
this.h5MusicPlayer.stop();
this.h5MusicPlayer.pause();
this.h5MusicPlayer.status = MusicShareApeTwo.STOP;
if (this.h5MusicPlayer.audio) {
this.h5MusicPlayer.audio.src = "";
}
}
this._hideMusicShareBox();
} catch (err) {
loger.warn("clear", err.message);
}
}
play() {
loger.log("play");
try {
if (this.h5MusicPlayer && ClassDataProxy.currentSceneTableId == ClassDataProxy.SCENE_DOC) {
this.h5MusicPlayer.resume()
this.h5MusicPlayer.status = MusicShareApeTwo.PLAY;
}
} catch (err) {
loger.warn("clear", err.message);
}
}
pause() {
loger.log("pause");
try {
if (this.h5MusicPlayer) {
this.h5MusicPlayer.pause()
this.h5MusicPlayer.status = MusicShareApeTwo.PAUSE;
}
} catch (err) {
loger.warn("clear", err.message);
}
}
stop() {
loger.log("伴音-stop");
this.musicShareFileList = {};//伴音数据
this._hideMusicShareBox();
try {
if (this.h5MusicPlayer) {
this.currPlayMusicId = 0;
this.h5MusicPlayer.rtmpURL = '';
this.h5MusicPlayer.musicId = 0;
this.h5MusicPlayer.nodeId = 0;
this.h5MusicPlayer.stop();
this.h5MusicPlayer.pause();
this.h5MusicPlayer.status = MusicShareApeTwo.STOP;
if (this.h5MusicPlayer.audio) {
this.h5MusicPlayer.audio.src = "";
}
}
this._hideMusicShareBox();
} catch (err) {
loger.warn("clear", err.message);
}
}
timerCounterUptate(timestamp) {
let minute = 0,
second = 0;
minute = Math.floor(timestamp / 60);
second = Math.floor(timestamp - minute * 60)
let timeValue = ((minute < 10) ? "0" : "") + minute;
timeValue += ((second < 10) ? ":0" : ":") + second;
return timeValue;
}
}
MusicShareApeTwo.prototype.STOP = MusicShareApeTwo.STOP = 0;
MusicShareApeTwo.prototype.PLAY = MusicShareApeTwo.PLAY = 1;
MusicShareApeTwo.prototype.PAUSE = MusicShareApeTwo.PAUSE = 2;
MusicShareApeTwo.prototype.SCENE_MUSIC_SHARE_CHANGE = MusicShareApeTwo.SCENE_MUSIC_SHARE_CHANGE = "scene_music_share_change";
export default MusicShareApeTwo;