Commit 2266d8b9 authored by huoshizhe's avatar huoshizhe

feat: 播放全部增加暂停功能

parent be34b0ce
...@@ -131,8 +131,8 @@ cc.Class({ ...@@ -131,8 +131,8 @@ cc.Class({
}, },
getDefaultData() { getDefaultData() {
const dataJson = ' [{"bgItem":{"url":"http://staging-teach.cdn.ireadabc.com/a962378295f3deb54e9f9329d59aa909.jpg","rect":{"x":427.1,"y":0,"width":1534.81,"height":892}},"hotZoneItemArr":[{"id":"1634813643232","index":0,"audio_url":"http://staging-teach.cdn.ireadabc.com/0b42398a12e1b2f075e9965e4d608765.mp3","itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":108.92,"y":450.35,"width":290.08,"height":290.08}},{"id":"1634813702995","index":1,"itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":493.28,"y":408.29,"width":290.08,"height":290.08}},{"id":"1634813712642","index":2,"audio_url":"http://staging-teach.cdn.ireadabc.com/784cd4188bf126d6c3c9395d9a807619.mp3","itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":789.18,"y":469.21,"width":290.08,"height":290.08}}]},{"bgItem":{"url":"http://staging-teach.cdn.ireadabc.com/281406244e10356325f075522f016ceb.jpg","rect":{"x":427.1,"y":0,"width":1534.81,"height":892}},"hotZoneItemArr":[{"id":"1634813750668","index":0,"itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":637.6,"y":419.17,"width":100.08,"height":100.08}},{"id":"1634813772152","index":1,"itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":791.35,"y":398.86,"width":85.57,"height":85.57}},{"id":"1634813784384","index":2,"itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":898.68,"y":374.21,"width":82.67,"height":82.67}},{"id":"1634813800497","index":3,"itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":1030.67,"y":342.3,"width":73.97,"height":73.97}}]},{"bgItem":{"url":"http://staging-teach.cdn.ireadabc.com/562f741288227a9a36a7ce63a152278e.jpg","rect":{"x":288.4,"y":0,"width":1058.19,"height":615}},"hotZoneItemArr":[{"id":"1634813836558","index":0,"audio_url":"http://staging-teach.cdn.ireadabc.com/7c1d1540233b6d050eae8215679104a8.mp3","itemType":"rect","fontScale":1.27734375,"imgScale":1,"mapScale":1.27734375,"gIdx":"1","useHand":true,"useBorder":true,"rect":{"x":9.6,"y":305,"width":69,"height":69}},{"id":"1634813857964","index":1,"audio_url":"http://staging-teach.cdn.ireadabc.com/495324991838775e49e3ca6593d432c9.mp3","itemType":"rect","fontScale":1.27734375,"imgScale":1,"mapScale":1.27734375,"gIdx":"1","useHand":true,"useBorder":true,"rect":{"x":115.6,"y":303,"width":67,"height":67}},{"id":"1634813868736","index":2,"audio_url":"http://staging-teach.cdn.ireadabc.com/3d0fea61d5d97f3caf04a9b738a0291b.mp3","itemType":"rect","fontScale":1.27734375,"imgScale":1,"mapScale":1.27734375,"gIdx":"1","useHand":true,"useBorder":true,"rect":{"x":209.6,"y":290,"width":65,"height":65}}]}]' // const dataJson = ' [{"bgItem":{"url":"http://staging-teach.cdn.ireadabc.com/a962378295f3deb54e9f9329d59aa909.jpg","rect":{"x":427.1,"y":0,"width":1534.81,"height":892}},"hotZoneItemArr":[{"id":"1634813643232","index":0,"audio_url":"http://staging-teach.cdn.ireadabc.com/0b42398a12e1b2f075e9965e4d608765.mp3","itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":108.92,"y":450.35,"width":290.08,"height":290.08}},{"id":"1634813702995","index":1,"itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":493.28,"y":408.29,"width":290.08,"height":290.08}},{"id":"1634813712642","index":2,"audio_url":"http://staging-teach.cdn.ireadabc.com/784cd4188bf126d6c3c9395d9a807619.mp3","itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":789.18,"y":469.21,"width":290.08,"height":290.08}}]},{"bgItem":{"url":"http://staging-teach.cdn.ireadabc.com/281406244e10356325f075522f016ceb.jpg","rect":{"x":427.1,"y":0,"width":1534.81,"height":892}},"hotZoneItemArr":[{"id":"1634813750668","index":0,"itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":637.6,"y":419.17,"width":100.08,"height":100.08}},{"id":"1634813772152","index":1,"itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":791.35,"y":398.86,"width":85.57,"height":85.57}},{"id":"1634813784384","index":2,"itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":898.68,"y":374.21,"width":82.67,"height":82.67}},{"id":"1634813800497","index":3,"itemType":"rect","fontScale":1.86640625,"imgScale":1,"mapScale":1.86640625,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":1030.67,"y":342.3,"width":73.97,"height":73.97}}]},{"bgItem":{"url":"http://staging-teach.cdn.ireadabc.com/562f741288227a9a36a7ce63a152278e.jpg","rect":{"x":288.4,"y":0,"width":1058.19,"height":615}},"hotZoneItemArr":[{"id":"1634813836558","index":0,"audio_url":"http://staging-teach.cdn.ireadabc.com/7c1d1540233b6d050eae8215679104a8.mp3","itemType":"rect","fontScale":1.27734375,"imgScale":1,"mapScale":1.27734375,"gIdx":"1","useHand":true,"useBorder":true,"rect":{"x":9.6,"y":305,"width":69,"height":69}},{"id":"1634813857964","index":1,"audio_url":"http://staging-teach.cdn.ireadabc.com/495324991838775e49e3ca6593d432c9.mp3","itemType":"rect","fontScale":1.27734375,"imgScale":1,"mapScale":1.27734375,"gIdx":"1","useHand":true,"useBorder":true,"rect":{"x":115.6,"y":303,"width":67,"height":67}},{"id":"1634813868736","index":2,"audio_url":"http://staging-teach.cdn.ireadabc.com/3d0fea61d5d97f3caf04a9b738a0291b.mp3","itemType":"rect","fontScale":1.27734375,"imgScale":1,"mapScale":1.27734375,"gIdx":"1","useHand":true,"useBorder":true,"rect":{"x":209.6,"y":290,"width":65,"height":65}}]}]'
// const dataJson = '[{"bgItem":{"url":"http://staging-teach.cdn.ireadabc.com/35bfd1d1342e1f2ea3db408afd072343.jpg","rect":{"x":651.79,"y":0,"width":471.43,"height":660}},"hotZoneItemArr":[{"id":"1636511068807","index":0,"audio_url":"http://staging-teach.cdn.ireadabc.com/989f78ee25c48624047f9f0275eb4193.mp3","itemType":"rect","fontScale":1.38671875,"imgScale":1,"mapScale":1.38671875,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":89.71,"y":329,"width":130,"height":130}},{"id":"1636536972082","index":1,"audio_url":"http://staging-teach.cdn.ireadabc.com/3e5c5d427828a8d65bf3f980e954da0c.mp3","itemType":"rect","fontScale":1.38671875,"imgScale":1,"mapScale":1.38671875,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":275.71,"y":370,"width":200,"height":200}},{"id":"1636536992261","index":2,"audio_url":"http://staging-teach.cdn.ireadabc.com/130feba39f7665f46adfc6765f86c6cd.mp3","itemType":"rect","fontScale":1.38671875,"imgScale":1,"mapScale":1.38671875,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":135.71,"y":230,"width":200,"height":200}}]}]' const dataJson = '[{"bgItem":{"url":"http://staging-teach.cdn.ireadabc.com/35bfd1d1342e1f2ea3db408afd072343.jpg","rect":{"x":651.79,"y":0,"width":471.43,"height":660}},"hotZoneItemArr":[{"id":"1636511068807","index":0,"audio_url":"http://staging-teach.cdn.ireadabc.com/989f78ee25c48624047f9f0275eb4193.mp3","itemType":"rect","fontScale":1.38671875,"imgScale":1,"mapScale":1.38671875,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":89.71,"y":329,"width":130,"height":130}},{"id":"1636536972082","index":1,"audio_url":"http://staging-teach.cdn.ireadabc.com/3e5c5d427828a8d65bf3f980e954da0c.mp3","itemType":"rect","fontScale":1.38671875,"imgScale":1,"mapScale":1.38671875,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":275.71,"y":370,"width":200,"height":200}},{"id":"1636536992261","index":2,"audio_url":"http://staging-teach.cdn.ireadabc.com/130feba39f7665f46adfc6765f86c6cd.mp3","itemType":"rect","fontScale":1.38671875,"imgScale":1,"mapScale":1.38671875,"gIdx":"0","useHand":true,"useBorder":true,"rect":{"x":135.71,"y":230,"width":200,"height":200}}]}]'
const data = JSON.parse(dataJson); const data = JSON.parse(dataJson);
return data; return data;
}, },
...@@ -285,14 +285,61 @@ cc.Class({ ...@@ -285,14 +285,61 @@ cc.Class({
let btn_loop = this.btn_audio.getComponent("btn_loop");//找到btn_loop let btn_loop = this.btn_audio.getComponent("btn_loop");//找到btn_loop
btn_loop.startPlay();//执行播放的方法 btn_loop.startPlay();//执行播放的方法
// this.picNode.getComponent('picNode').autoTouchAll() if (!this._playAllData) {
this._playAllData = {
currentPageIdx: this.curPage,
currentPicIdx: 0,
currentAudioId: null
}
}
if (this.curPage != this._playAllData.currentPageIdx) {
this._playAllData.currentPageIdx = this.curPage;
this._playAllData.currentPicIdx = 0;
}
const picNodeComponent = this.picNode.getComponent('picNode');
const hitItemComponent = picNodeComponent._items.children[this._playAllData.currentPicIdx].getComponent('hitItem');
hitItemComponent.showBox();
if (this._playAllData.currentAudioId === null) {
const url = this.data[this._playAllData.currentPageIdx].hotZoneItemArr[this._playAllData.currentPicIdx].audio_url;
cc.assetManager.loadRemote(url, (err, audioClip) => {
if (err) return
if (!this.isPlaying) return
this._playAllData.currentAudioId = cc.audioEngine.play(audioClip, false, 0.8);
cc.audioEngine.setFinishCallback(this._playAllData.currentAudioId, () => {
const picNodeComponent = this.picNode.getComponent('picNode');
const hitItemComponent = picNodeComponent._items.children[this._playAllData.currentPicIdx].getComponent('hitItem');
hitItemComponent.hideBox();
this._playAllData.currentPicIdx++;
if (this._playAllData.currentPicIdx >= this.data[this._playAllData.currentPageIdx].hotZoneItemArr.length) {
this._playAllData = null;
this.stopAll();
} else {
this._playAllData.currentAudioId = null;
this.playAll();
}
});
});
} else {
cc.audioEngine.resume(this._playAllData.currentAudioId);
}
}, },
stopAll() { stopAll() {
this.isPlaying = false; this.isPlaying = false;
let btn_loop = this.btn_audio.getComponent("btn_loop");//找到btn_loop let btn_loop = this.btn_audio.getComponent("btn_loop");//找到btn_loop
btn_loop.stopPlay();//执行暂停的方法 btn_loop.stopPlay();//执行暂停的方法
// this.picNode.getComponent('picNode').stopTouchAll() const picNodeComponent = this.picNode.getComponent('picNode');
picNodeComponent._items.children.forEach(item => {
const hitItemComponent = item.getComponent('hitItem')
hitItemComponent.hideBox();
});
if (this._playAllData && this._playAllData.currentAudioId !== undefined) {
cc.audioEngine.pause(this._playAllData.currentAudioId);
}
}, },
/** 左移动 */ /** 左移动 */
leftMove() { leftMove() {
......
...@@ -139,14 +139,25 @@ cc.Class({ ...@@ -139,14 +139,25 @@ cc.Class({
onClickHide() { onClickHide() {
this.sprite.node.active = false this.sprite.node.active = false
this.hideBox() this.hideBox()
this.stopAudio()
},
/**隐藏边框 */
showBox() {
this.quan.active = true
this.hand.active = false
// this.btnX.active = true
// this.icon_stop.active = true
this.quan.getComponent(cc.Sprite).spriteFrame = this.quan_lan;
}, },
/**隐藏边框 */ /**隐藏边框 */
hideBox() { hideBox() {
this.quan.active = false // this.quan.active = false
// this.btnX.active = false // this.btnX.active = false
this.icon_stop.active = false // this.icon_stop.active = false
this.stopAudio() this.hand.active = false
this.quan.getComponent(cc.Sprite).spriteFrame = this.quan_huang;
}, },
/** 播放音乐 */ /** 播放音乐 */
......
...@@ -5,6 +5,6 @@ ...@@ -5,6 +5,6 @@
}, },
"android": { "android": {
"sceneName": "Book_Read", "sceneName": "Book_Read",
"version": "3a34d" "version": "19dbd"
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment