参考音乐路径:https://testcdn.chinaxwz.cn/game/dyds/music/song01.mp3 在浏览器中打开,音乐总时长为92s。 在代码中监听播放完成事件:
if (!this.bgmAudio) {
this.bgmAudio = window.platform.createAudioContext();
this.bgmAudio.onPlay(this.musicOnPlay.bind(this));
this.bgmAudio.onEnded(this.musicPlayCompleted.bind(this));
}
在播放完成的回调中,打印音乐当前播放的位置,预期希望打印出来的事件等于音乐总时长。
private musicPlayCompleted(): void {
this._gameView.resetView();
// 当前播放时长,单位ms for debug
console.log("musicPlayCompleted:当前的播放时长:" + this.bgmAudio.currentTime);
// end
}
结果打印出来的时间: musicPlayCompleted:当前的播放时长:89.234286
为什么会差了个接近2s的时间呢?
麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)