Commit 082b2e0c authored by jeff's avatar jeff

更新audio

parent ee97fab7
......@@ -8,16 +8,16 @@ cc.Class({
tiao: cc.Node,
moveBtn: cc.Node
},
onload() {
onLoad() {
this._clip = null
this._play = false
this._audioId = null
this._totoalTime = null
this._nowTime = null
this._nowTime = 0
this._pause = false
this.node.active = false
this.clip = null
},
onEnable() {
this._nowTime = 0
cc.systemEvent.on('stopBgMusic', this.onEvent, this)
this.moveBtn.on(cc.Node.EventType.TOUCH_START, this.onTouchStart, this)
this.moveBtn.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMove, this)
......@@ -37,38 +37,38 @@ cc.Class({
init(url) {
if (!this.au) {
this.au = new cc.AudioSource()
}
this.onEvent()
this.playBtn.active = true
this.pauseBtn.active = false
this.node.active =false
this.node.active = false
cc.assetManager.loadRemote(url, (err, audioClip) => {
if (err) return
this.clip = audioClip
this._nowTime = 0
this._totoalTime = audioClip.duration
this.label.string = '0:00/' + this.transTime(this._totoalTime)
this.tiao.children[0].getComponent(cc.Sprite).fillRange = 0
this.tiao.children[1].x = 12
this.onAudioFinish()
this.au.clip = this.clip
this.node.active = true
})
},
onAudioFinish() {
if (this._audioId != null) {
if (this._play) {
this.pauseBtn.active = false
this.playBtn.active = true
}
this._play = false
}
this._nowTime = 0
this._audioId = cc.audioEngine.play(this.clip)
cc.audioEngine.pause(this._audioId)
cc.audioEngine.setFinishCallback(this._audioId, this.onAudioFinish.bind(this))
},
onTouchStart() {
if (this._play) {
this._pause = true
this._play = false
cc.audioEngine.pause(this._audioId)
this.au.pause()
}
},
......@@ -90,24 +90,28 @@ cc.Class({
if (this._pause) {
this._play = true
this._pause = false
cc.audioEngine.resume(this._audioId)
this.au.play()
}
cc.audioEngine.setCurrentTime(this._audioId, this._totoalTime * (this.moveBtn.x - 12) / 364)
this._nowTime = this._totoalTime * (this.moveBtn.x - 12) / 364
this.au.setCurrentTime(this._nowTime)
},
onPlay() {
if (this._play) return
this._play = true
this.pauseBtn.active = true
this.playBtn.active = false
this._play = true
cc.audioEngine.resume(this._audioId)
this.au.play()
this.au.setCurrentTime(this._nowTime)
cc.systemEvent.emit('stopWordsMusic')
},
onPause() {
if (!this._play) return
this._play = false
this.pauseBtn.active = false
this.playBtn.active = true
this._play = false
cc.audioEngine.pause(this._audioId)
this.au.stop()
},
/** 定时回调 */
......@@ -115,10 +119,16 @@ cc.Class({
if (!this._play) return
this._nowTime += dt
this.label.string = this.transTime(this._nowTime) + '/' + this.transTime(this._totoalTime)
if (this._nowTime > this._totoalTime) this._nowTime = this._totoalTime
if (this._nowTime > this._totoalTime) {
this._nowTime = this._totoalTime
}
let scale = this._nowTime / this._totoalTime
this.tiao.children[0].getComponent(cc.Sprite).fillRange = scale
this.tiao.children[1].x = 12 + 364 * scale
if (this._nowTime == this._totoalTime) {
this.onPause()
this._nowTime = 0
}
},
onEvent() {
......
......@@ -1948,7 +1948,7 @@
"__id__": 57
}
],
"_active": true,
"_active": false,
"_components": [
{
"__id__": 59
......
......@@ -295,6 +295,7 @@ cc.Class({
let url = data.bgItem.bgAudioUrl
if (url && url != '') {
this.bgAudioNode.active =true
this.bgAudioNode.getComponent('audioItem').init(url)
} else {
this.bgAudioNode.active = false
......
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