s***@qq.com
s***@qq.com
  • 发布:2019-08-20 18:47
  • 更新:2020-06-24 12:06
  • 阅读:2927

【报Bug】背景音频管理器 backgroundAudioManager 回调函数不调用

分类:uni-app

详细问题描述

项目中用到了背景音频管理器 backgroundAudioManager,遇到了一些问题

重现步骤

测试了三个网络音频文件,第一次打开正常,后面再打开音频能正常加载,但是时间不更新,回调函数 onPlay 没有调用。
另外还发现同样的音频链接,浏览器打开速度快,App打开慢,这个是什么原因呢?

期望设置了新参数能正确回调函数

IDE运行环境说明

使用HBuilderX,版本是最新的 2.2.2.20190816

uni-app运行环境说明

iOS app,Android App也有同样的问题,demo项目通过HBuilderX创建的默认工程

附件

运行log

18:11:52.946 [LOG] : App Launch at App.vue:4   
18:11:52.970 [LOG] : App Show at App.vue:7   
18:11:53.945 [LOG] : audio test begin... at pages/index/index.vue:25   
18:11:53.969 [LOG] : init bgAudioMannager... at pages/index/index.vue:30   
18:11:56.959 [LOG] : ### MUSIC_PARAMS_INIT ###, [Object] {"title":"AUDIO-01","coverImgUrl":"https://assets.hervillageclub.com/images/8bed8f41c54d4a1881816db97ab937...}  at pages/index/index.vue:75   
18:11:56.982 [LOG] : onWaiting at pages/index/index.vue:53   
18:11:57.005 [LOG] : onPlay, [Number] 1429.368  at pages/index/index.vue:34   
18:12:16.043 [LOG] : ### MUSIC_PARAMS_INIT ###, [Object] {"title":"AUDIO-02","coverImgUrl":"https://assets.hervillageclub.com/images/8bed8f41c54d4a1881816db97ab937...}  at pages/index/index.vue:75   
18:12:17.036 [LOG] : onWaiting at pages/index/index.vue:53 

通过log可以看到后面播放音频时,回调函数只调用了onWaiting,音频开始播放后onPlay没有调用

偶尔也会有JS Framework错误提示

06:33:53.571 [ERROR] : [JS Framework] Failed to execute the callback function:  
06:33:53.571  ReferenceError: Can't find variable: nan __ERROR 

代码片段

<template>  
    <view class="content">  
        <view class="text-area">  
            <text class="title">{{title}}播放进度: {{currentTime}} / {{duration}}</text>  
        </view>  
        <button class="btn" @click="onAudioTest(0)">测试音频1</button>  
        <button class="btn" @click="onAudioTest(1)">测试音频2</button>  
        <button class="btn" @click="onAudioTest(2)">测试音频3</button>  
    </view>  
</template>  

<script>  

const bgAudioMannager = uni.getBackgroundAudioManager()  

export default {  
    data() {  
        return {  
            title: 'Hello',  
            currentTime: 0,  
            duration: 0,  
        }  
    },  
    mounted () {  
        console.log('audio test begin...')  
        this.initAudio()  
    },  
    methods: {  
        initAudio () {  
            console.log('init bgAudioMannager...')  
            let audio = bgAudioMannager  
            audio.onPlay(() => {  
                this.duration = audio.duration  
                console.log('onPlay', this.duration)  
            })  
            audio.onCanplay(() => {  
                console.log('onCanplay')  
                this.duration = audio.duration  
            })  
            audio.onStop(() => {  
                console.log('onStop')  
            })  
            audio.onEnded(() => {  
                console.log('onEnded')  
            })  
            audio.onPause(() => {  
                console.log('onPause')  
            })  
            audio.onTimeUpdate(() => {  
                this.currentTime = audio.currentTime  
            })  
            audio.onWaiting(() => {  
                console.log('onWaiting')  
            })  
            audio.onSeeking(() => {  
                console.log('onSeeking')  
            })  
            audio.onSeeked(() => {  
                this.currentTime = audio.currentTime  
                console.log('onSeeked', this.currentTime)  
            })  
            audio.onNext(() => {  
                console.log('onNext')  
            })  
            audio.onPrev(() => {  
                console.log('onPrev')  
            })  
            audio.onError((res) => {  
                console.error('audio.onError', res)  
            })  
        },  
        startAudio (params) {  
            let audio = bgAudioMannager  
            if (params) {  
                console.log('### MUSIC_PARAMS_INIT ###', params)  
                if (params.title) {  
                    audio.title = params.title  
                }  
                if (params.startTime !== undefined) {  
                    audio.startTime = params.startTime  
                }  
                // 当设置了新的 src 时,会自动开始播放  
                if (params.src) {  
                    audio.src = params.src  
                }  
                if (params.coverImgUrl) {  
                    audio.coverImgUrl = params.coverImgUrl  
                }  
            }  
        },  
        onAudioTest (index) {  
            if (index === 0) {  
                let params = {  
                    "title": "AUDIO-01",  
                    "coverImgUrl": "https://assets.hervillageclub.com/images/8bed8f41c54d4a1881816db97ab937bf.png",  
                    "src": "https://cdn.hervillageclub.com/202010100837/d41e7ca519ff3368f0490cfbe5e77683/d632bff2-f67c-4893-9e9a-2a0719930102",  
                    "startTime": 10  
                }  
                this.startAudio(params)  
                this.title = params.title  
            } else if (index === 1) {  
                let params = {  
                    "title": "AUDIO-02",  
                    "coverImgUrl": "https://assets.hervillageclub.com/images/8bed8f41c54d4a1881816db97ab937bf.png",  
                    "src": "https://cdn.hervillageclub.com/202010100838/aca72ab091ec5cf1866cc6f7fffd4d05/ff6f9ffd-c412-467d-94da-bd415f320308",  
                    "startTime": 20  
                }  
                this.startAudio(params)  
                this.title = params.title  
            } else if (index === 2) {  
                let params = {  
                    "title": "AUDIO-03",  
                    "coverImgUrl": "https://assets.hervillageclub.com/images/8bed8f41c54d4a1881816db97ab937bf.png",  
                    "src": "https://cdn.hervillageclub.com/202010100838/f56edd47b82a0917f8971dac8b39289b/5965b210-df55-41b5-bcb1-a3c7772dc5fe",  
                    "startTime": 30  
                }  
                this.startAudio(params)  
                this.title = params.title  
            }  
        }  
    }  
}  
</script>  

<style>  
.content {  
    display: flex;  
    flex-direction: column;  
    align-items: center;  
    justify-content: center;  
}  

.text-area {  
    margin-top: 40upx;  
    display: flex;  
    justify-content: center;  
}  

.title {  
    font-size: 26upx;  
    color: #8f8f94;  
}  
.btn {  
    width: 400upx;  
    margin-top: 10upx;  
}  
</style>  

另外附件是demo压缩包。

2019-08-20 18:47 负责人:无 分享
已邀请:
s***@qq.com

s***@qq.com (作者)

请求付费解决,邮件已发,麻烦回复一下,谢谢~

m***@95jw.cn

m***@95jw.cn

同样出问题,,播放14次后, onEnded回调不表用,,使用的是apa版本 20190823

1***@qq.com

1***@qq.com

楼主这个是个啥啊?

强尼

强尼 - NodeJs全栈实践者

同样遇到这个问题,ios上一曲下一曲回调不起作用,我们是开发音频播放app的,现在开发到一半卡在这里没法进行,希望官方重视这个问题。

  • s***@qq.com (作者)

    官方的播放器BUG太多了,特别是Android。我们已经自己写了插件,不用系统自带的播放器了,现在系统栏也能实现进度条了,完美

    2020-06-28 20:55

1***@qq.com

1***@qq.com

安卓的通知栏播放和息屏播放这个可以了吗

  • s***@qq.com (作者)

    Android官方不会有的。我们已经自己写了插件,不用系统自带的播放器了,现在系统栏也能实现进度条了,完美

    2020-06-28 20:55

  • 1***@qq.com

    回复 s***@qq.com:能否告诉下怎么搞的呢?有没有代码参考下呢

    2020-07-05 23:51

  • s***@qq.com (作者)

    回复 1***@qq.com: 这个得自己实现了,公司的私有代码比较多,不方便共享

    2020-07-09 09:24

该问题目前已经被锁定, 无法添加新回复