|
@@ -17,24 +17,26 @@ function matchWare(wareList, wareId) {
|
|
|
|
|
|
class LessonScene extends scene {
|
|
|
constructor(scope) {
|
|
|
- super(scope);
|
|
|
- this.timer = null; //记录定时器
|
|
|
- this.isBack = false; //是否返回上个场景
|
|
|
- this.videoPlayer = null; //视频播放器
|
|
|
- this.courseId = null; //记录课程ID
|
|
|
- this.lessonId = null; //记录课ID
|
|
|
- this.wareList = null; //记录课件列表
|
|
|
- this.curWareId = null; //当前课件的id
|
|
|
- this.curWareType = null; //当前课件的类型
|
|
|
- this.curWareIndex = 0; //当前课件在课件列表中的索引
|
|
|
- this.curImageList = null; //当前图片课件的图片列表
|
|
|
- this.curImageIndex = null;//当前图片在列表中的索引
|
|
|
- this.videoPosition = {
|
|
|
- top: 270,
|
|
|
- left: 790,
|
|
|
- width: 1072,
|
|
|
- height: 603,
|
|
|
- };
|
|
|
+ super(scope);
|
|
|
+ this.timer = null; //记录定时器
|
|
|
+ this.isBack = false; //是否返回上个场景
|
|
|
+ this.videoPlayer = null; //视频播放器
|
|
|
+ this.courseId = null; //记录课程ID
|
|
|
+ this.lessonId = null; //记录课ID
|
|
|
+ this.wareList = null; //记录课件列表
|
|
|
+ this.curWareId = null; //当前课件的id
|
|
|
+ this.curWareType = null; //当前课件的类型
|
|
|
+ this.curWareIndex = 0; //当前课件在课件列表中的索引
|
|
|
+ this.curImageList = null; //当前图片课件的图片列表
|
|
|
+ this.curImageIndex = null;//当前图片在列表中的索引
|
|
|
+ this.curAudioList = null; //当前音频课件的音频列表
|
|
|
+ this.curAudioIndex = 0; //当前音频在列表中的索引
|
|
|
+ this.videoPosition = {
|
|
|
+ top: 270,
|
|
|
+ left: 790,
|
|
|
+ width: 1072,
|
|
|
+ height: 603,
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -109,6 +111,8 @@ class LessonScene extends scene {
|
|
|
case Consts.TYPE_VIDEO:
|
|
|
item.icon = 'assets/img/LessonScene/video.png';
|
|
|
break;
|
|
|
+ case Consts.TYPE_AUDIOBOOK:
|
|
|
+ item.icon = 'assets/img/LessonScene/audio.png';
|
|
|
}
|
|
|
return `<div class="ware-item-frame">
|
|
|
<div class="ware-type">${item.text}</div>
|
|
@@ -175,6 +179,26 @@ class LessonScene extends scene {
|
|
|
this.renderImageView();
|
|
|
}
|
|
|
break;
|
|
|
+ case Consts.TYPE_AUDIOBOOK:
|
|
|
+ let audioViewDom =
|
|
|
+ `
|
|
|
+ <div id="view-full-screen" fe-role="Widget" class="view-full-screen-img"></div>
|
|
|
+ <div id="view-previous" fe-role="Widget">
|
|
|
+ <div class="transparent-btn">上一页</div>
|
|
|
+ </div>
|
|
|
+ <div id="view-page">1/1</div>
|
|
|
+ <div id="view-next" fe-role="Widget">
|
|
|
+ <div class="transparent-btn">下一页</div>
|
|
|
+ </div>
|
|
|
+ `;
|
|
|
+ document.getElementById('view-bottom').innerHTML = audioViewDom;
|
|
|
+ this.moye.root.reRender();
|
|
|
+ this.curAudioList = list;
|
|
|
+ if (this.curAudioList.length > 0) {
|
|
|
+ this.curAudioIndex = 0;
|
|
|
+ this.renderAudioView();
|
|
|
+ }
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
@@ -185,11 +209,54 @@ class LessonScene extends scene {
|
|
|
*/
|
|
|
renderImageView() {
|
|
|
const curImage = this.curImageList[this.curImageIndex];
|
|
|
- document.getElementById('view-page').innerHTML = (this.curImageIndex + 1) + '/' + this.curImageList.length; const imageDom = `<img src=${curImage.url} />`
|
|
|
+ document.getElementById('view-page').innerHTML = (this.curImageIndex + 1) + '/' + this.curImageList.length;
|
|
|
+ const imageDom = `<img src=${curImage.url} />`
|
|
|
document.getElementById('view-content').innerHTML = imageDom;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 渲染音频视图
|
|
|
+ */
|
|
|
+ renderAudioView() {
|
|
|
+ const curAudio = this.curAudioList[this.curAudioIndex];
|
|
|
+ const { img, audio, type } = curAudio;
|
|
|
+ let imgPath = (img || {}).path || '';
|
|
|
+ let audioUrl = (audio || {}).url;
|
|
|
+ let footer = document.getElementById('view-page');
|
|
|
+ if (footer) {
|
|
|
+ footer.innerHTML = (this.curAudioIndex + 1) + '/' + this.curAudioList.length;
|
|
|
+ }
|
|
|
+ let content = document.getElementById('view-content');
|
|
|
+ // 1.更换背景图片
|
|
|
+ let imgHTML = `<img src="${Consts.IMG_PATH}/${imgPath}" />`;
|
|
|
+ content.innerHTML = imgHTML;
|
|
|
+ // 2.根据是否有无audioURL来控制面板及audio的展现
|
|
|
+ if (type === Consts.TYPE_AUDIOBOOK && audioUrl) {
|
|
|
+ let audioElement = document.createElement('audio');
|
|
|
+ audioElement.setAttribute('id', 'courseware-audio');
|
|
|
+ audioElement.setAttribute('src', audioUrl);
|
|
|
+ let controlsElement = document.createElement('div');
|
|
|
+ controlsElement.setAttribute('class', 'audio-controls');
|
|
|
+ controlsElement.setAttribute('fe-role', 'Switch');
|
|
|
+ let controlsBtns = `
|
|
|
+ <!-- 播放/暂停 -->
|
|
|
+ <div id="audio-play" class="audio-controls-item btn-play paused" fe-role="Widget"></div>
|
|
|
+ <!-- 有声/静音 -->
|
|
|
+ <div id="audio-mute" class="audio-controls-item btn-mute" fe-role="Widget"></div>
|
|
|
+ <!-- 下一个音频 -->
|
|
|
+ <div id="audio-next" class="audio-controls-item btn-next" fe-role="Widget"></div>
|
|
|
+ <!-- 上一个音频 -->
|
|
|
+ <div id="audio-last" class="audio-controls-item btn-last" fe-role="Widget"></div>
|
|
|
+ `;
|
|
|
+ controlsElement.innerHTML = controlsBtns;
|
|
|
+ content.appendChild(audioElement);
|
|
|
+ content.appendChild(controlsElement);
|
|
|
+ this.moye.root.reRender();
|
|
|
+ //FocusEngine.getWidgetById('audio-play').focus();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 渲染视频视图
|
|
|
*/
|
|
|
renderVideoView(name, url, type) {
|
|
@@ -270,12 +337,72 @@ class LessonScene extends scene {
|
|
|
this.moye.root.reRender();
|
|
|
this.renderImageView();
|
|
|
break;
|
|
|
+ case Consts.TYPE_AUDIOBOOK:
|
|
|
+ let audioViewDom =
|
|
|
+ `
|
|
|
+ <div id="view-full-screen" fe-role="Widget" class="view-full-screen-img"></div>
|
|
|
+ <div id="view-previous" fe-role="Widget">
|
|
|
+ <div class="transparent-btn">上一页</div>
|
|
|
+ </div>
|
|
|
+ <div id="view-page">1/1</div>
|
|
|
+ <div id="view-next" fe-role="Widget">
|
|
|
+ <div class="transparent-btn">下一页</div>
|
|
|
+ </div>
|
|
|
+ `;
|
|
|
+ document.getElementById('view-bottom').innerHTML = audioViewDom;
|
|
|
+ this.moye.root.reRender();
|
|
|
+ this.renderAudioView();
|
|
|
+ break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 音频播放控制
|
|
|
+ */
|
|
|
+ audioPlayControl(eventId) {
|
|
|
+ let targetAudio = document.getElementById('courseware-audio');
|
|
|
+ if (!targetAudio) { return; }
|
|
|
+ switch (eventId) {
|
|
|
+ case 'audio-play':
|
|
|
+ let playBtn = document.querySelector('#audio-play');
|
|
|
+ if (targetAudio.paused) {
|
|
|
+ targetAudio.play();
|
|
|
+ playBtn.classList.remove('paused');
|
|
|
+ } else {
|
|
|
+ targetAudio.pause();
|
|
|
+ playBtn.classList.add('paused');
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'audio-mute':
|
|
|
+ let muteBtn = document.querySelector('#audio-mute');
|
|
|
+ if (targetAudio.muted) {
|
|
|
+ targetAudio.muted = false;
|
|
|
+ muteBtn.classList.remove('muted');
|
|
|
+ } else {
|
|
|
+ targetAudio.muted = true;
|
|
|
+ muteBtn.classList.add('muted');
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'audio-next':
|
|
|
+ if (this.curAudioIndex < this.curAudioList.length -1) {
|
|
|
+ this.curAudioIndex += 1;
|
|
|
+ this.renderAudioView();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'audio-last':
|
|
|
+ if (this.curAudioIndex > 0) {
|
|
|
+ this.curAudioIndex -= 1;
|
|
|
+ this.renderAudioView();
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 记录播放行为事件
|
|
|
*/
|
|
|
postPlayRecord(lessonId, courseId, playStopTime=1){
|
|
@@ -312,7 +439,7 @@ class LessonScene extends scene {
|
|
|
onResume(data) {
|
|
|
if (!data) { return; }
|
|
|
//更新下当前的课件信息
|
|
|
- const { curWareIndex, curImageList, curImageIndex } = data;
|
|
|
+ const { curWareIndex, curImageList, curImageIndex, curAudioList, curAudioIndex } = data;
|
|
|
this.curWareIndex = curWareIndex;
|
|
|
this.curWareId = this.wareList[curWareIndex].id;
|
|
|
this.curWareType = this.wareList[curWareIndex].type;
|
|
@@ -322,6 +449,12 @@ class LessonScene extends scene {
|
|
|
if (curImageIndex) {
|
|
|
this.curImageIndex = curImageIndex;
|
|
|
}
|
|
|
+ if (curAudioList) {
|
|
|
+ this.curAudioList = curAudioList;
|
|
|
+ }
|
|
|
+ if (curAudioIndex) {
|
|
|
+ this.curAudioIndex = curAudioIndex;
|
|
|
+ }
|
|
|
//更新左侧焦点位置
|
|
|
this.moye.root.getWidgetById(`item-${this.curWareType}-${this.curWareId}-${this.curWareIndex}`).focus();
|
|
|
//更新右侧视图
|
|
@@ -331,6 +464,11 @@ class LessonScene extends scene {
|
|
|
|
|
|
onOK() {
|
|
|
const leaf = FocusEngine.getFocusedLeaf();
|
|
|
+ // 拦截音频控制相关事件单独处理
|
|
|
+ if (leaf.id && leaf.id.startsWith('audio')) {
|
|
|
+ this.audioPlayControl(leaf.id);
|
|
|
+ return;
|
|
|
+ }
|
|
|
switch (leaf.id) {
|
|
|
case 'view-video-start':
|
|
|
if (this.curWareType == Consts.TYPE_VIDEO) {
|
|
@@ -363,6 +501,22 @@ class LessonScene extends scene {
|
|
|
wareList: this.wareList,
|
|
|
curWareIndex: this.curWareIndex,
|
|
|
});
|
|
|
+ } else if (this.curWareType === Consts.TYPE_AUDIOBOOK) {
|
|
|
+ // 全屏前移除audio标签
|
|
|
+ let audio = document.getElementById('courseware-audio');
|
|
|
+ let controls = document.querySelector('.audio-controls');
|
|
|
+ if (audio) {
|
|
|
+ document.getElementById('view-content').removeChild(audio);
|
|
|
+ }
|
|
|
+ if (controls) {
|
|
|
+ document.getElementById('view-content').removeChild(controls);
|
|
|
+ }
|
|
|
+ this.showScene(require('./AudioWareFullScreenScene.js'), {
|
|
|
+ wareList: this.wareList,
|
|
|
+ curWareIndex: this.curWareIndex,
|
|
|
+ curAudioList: this.curAudioList,
|
|
|
+ curAudioIndex: this.curAudioIndex,
|
|
|
+ });
|
|
|
}
|
|
|
this.postPlayRecord(this.cur_item_id, this.courseId);
|
|
|
break;
|
|
@@ -371,6 +525,10 @@ class LessonScene extends scene {
|
|
|
this.curImageIndex -= 1;
|
|
|
this.renderImageView();
|
|
|
}
|
|
|
+ if (this.curWareType === Consts.TYPE_AUDIOBOOK && this.curAudioIndex - 1 >= 0) {
|
|
|
+ this.curAudioIndex -= 1;
|
|
|
+ this.renderAudioView();
|
|
|
+ }
|
|
|
this.postPlayRecord(this.curWareId, this.courseId);
|
|
|
break;
|
|
|
case 'view-next':
|
|
@@ -378,6 +536,10 @@ class LessonScene extends scene {
|
|
|
this.curImageIndex += 1;
|
|
|
this.renderImageView();
|
|
|
}
|
|
|
+ if (this.curWareType === Consts.TYPE_AUDIOBOOK && this.curAudioIndex + 1 < this.curAudioList.length) {
|
|
|
+ this.curAudioIndex += 1;
|
|
|
+ this.renderAudioView();
|
|
|
+ }
|
|
|
this.postPlayRecord(this.curWareId, this.courseId);
|
|
|
break;
|
|
|
default:
|