• 【uniapp】audio.onTimeUpdate在微信小程序上面的问题


    1、h5的audio.onTimeUpdate是多个都会执行,微信小程序会覆盖,只执行最新一个。

    方法1:给audio对象添加一个属性,进度更新监听要执行的方法数组audio.onTimeUpdateList。然后在需要启动监听的地方执行监听,比如在播放事件onPlay中。再加个属性onTimeUpdateExist,避免h5重复监听

    //声明进度更新事件
                    that.audio.onTimeUpdateList=[{name:that.modelName+"-audio",func:function(){
                        console.log("onTimeUpdate1");
                        // console.log("onTimeUpdate");
                        if (!that.seek) {
                            that.current = that.audio.currentTime
                        }
                        if (!that.duration) {
                            that.duration = that.audio.duration
                        }
                    }}];
    //音频播放事件
                    that.audio.onPlay(() => {
                        console.log("onPlay");
                        
                        //实现进度监听事件//h5的audio.onTimeUpdate多个都会执行,微信小程序会覆盖,只执行最新一个。
                        if(!that.audio.onTimeUpdateExist && that.audio.onTimeUpdateList){
                            that.audio.onTimeUpdateExist=true;
                            //进度更新事件
                            that.audio.onTimeUpdate(() => {
                                for (var i = 0; i < that.audio.onTimeUpdateList.length; i++) {
                                    that.audio.onTimeUpdateList[i].func();
                                }
                            })
                        }
                    }) 

    2、在微信小程序使用audio.seek后,audio.onTimeUpdate监听失效,在onSeeked使用audio的属性例如paused、duration后恢复。

    方法1:在完成进度设置事件onSeeked中或onCanplay事件中使用audio.paused。

    //音频完成更改进度事件
                        audioBottomInfo.audio.onSeeked(() => {
                            console.log("onSeeked:"+audioBottomInfo.audio.paused); that.seek = false; })
  • 相关阅读:
    Auto.js常用控件整理
    python对接口sign签名操作
    # 859.亲密字符串
    linux系统如何挂载FTP共享文件
    解决“Tomcat控制台输出乱码问题”
    关于“Unknown or unsupported command 'install'”问题解决的小结
    输出九九乘法表
    python webdriver混合驱动测试框架(数据驱动+关键字驱动)
    python webdriver关键字框架
    python webdriver测试框架--数据驱动DB驱动
  • 原文地址:https://www.cnblogs.com/lanofsky/p/13986217.html
Copyright © 2020-2023  润新知