8***@qq.com
8***@qq.com
  • 发布:2022-12-12 11:51
  • 更新:2022-12-14 10:49
  • 阅读:579

在自定义组件中uni.createInnerAudioContext(),只能播放一个音频,其他的不能播放

分类:uni-app

我自己写了一个音频播放组件,这是js内容。在列表中使用组件时,只能播放一个,暂停或者结束了,点击播放另一个都无效,播放不了。监听事件中也无数据。
在v-for中加载了多个这个组件

interface IProps {  
        url: any,  
        activeColor?: string,  
    }  
    const props = defineProps<IProps>();  
    toRefs(props);  
    const duration = ref(100);  
    const currentTime = ref(0);  
    const status = ref<boolean>(false);  
    const innerAudioContext = uni.createInnerAudioContext();  
    innerAudioContext.src = props.url;  
    innerAudioContext.sessionCategory = "ambient";  
    innerAudioContext.onCanplay(() => {  
        innerAudioContext.duration;  
        duration.value = innerAudioContext.duration;  
    });  
    innerAudioContext.onError((e) => {  
        console.log('error', e)  
    });  
    innerAudioContext.onPlay((e) => {  
        console.log('onPlay', e)  
    });
2022-12-12 11:51 负责人:无 分享
已邀请:
8***@qq.com

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

找到原因了。

innerAudioContext.src = props.url;    
这一段代码放在 播放的点击事件去写,就可以了。不要放在外部,或者onLoad,create里面

要回复问题请先登录注册