2***@qq.com
2***@qq.com
  • 发布:2025-10-31 15:51
  • 更新:2025-10-31 15:55
  • 阅读:18

安卓9版本的设备 视频实例 无法调起play

分类:nvue

app进入之后会下载视频,下载完之后循环播放视频,每一次播放都会创建视频实例(createVideoContext方法)然后销毁实例,但是有些机器可能播放一两天然后就无法播放了,通过打印日志发现,一旦触发了播放不了视频,每次调用实例play就无法执行了,无论是本地路径的视频还是网络路径的视频连接都无法触发播放了。使用try catch也没办法打印错误。只是调用这个play方法的时候没有任何反应。

startAutoSwitch() {  
    let self = this  
    self.stopAutoSwitch();  

    if (!self.videoList || self.videoList.length === 0) {  
        return;  
    }  

    if (self.currentIndex >= self.videoList.length) {  
        self.currentIndex = 0;  
    }  

    const currentItem = self.videoList[self.currentIndex];  
    if (!currentItem) {  
        return;  
    }  

    const duration = currentItem.duration || 5000;  
    const nextIndex = (self.currentIndex + 1) % self.videoList.length;  

    self.timer = setTimeout(() => {  
        try {  
            // 清理当前视频上下文  
            self.clearVideoContext();  

            // 切换到下一个视频  
            self.currentIndex = nextIndex;  

            // 创建新视频的上下文  
            self.createCurrentVideoContext();  

            // 播放新视频  
            self.play();  
        } catch (e) {  
            console.log('自动切换失败:', e);  
        }  
    }, duration + self.loading_time);  
},  
play() {  
    let self = this  
    if (!self.videoList || self.videoList.length === 0) {  
        return;  
    }  

    self.stopPreviousVideo()  

    if (self.currentIndex >= self.videoList.length) {  
        self.currentIndex = 0;  
    }  

    if (self.videoList[self.currentIndex].type === 'video') {  

        this.$nextTick(() => {  
            // 确保视频上下文存在  
            if (!self.videoContext) {  
                self.createCurrentVideoContext();  
            }  

            if (self.videoContext) {  
                try {  
                    // TODO 问题就出在这里了,调用play 无反应  
                    self.videoContext.play()  
                } catch (e) {  
                    console.log('视频播放失败:', e);  
                    self.startAutoSwitch();  
                }  
            } else {  
                console.log('视频上下文不存在');  
                self.startAutoSwitch();  
            }  
        })  
    } else {  
        self.startAutoSwitch()  
    }  
},  
onplay() {  
    let self = this  
    if (self.playTimer) {  
        clearTimeout(self.playTimer)  
        self.playTimer = null  
    }  
    self.playTimer = setTimeout(() => {  
        self.startAutoSwitch()  
    }, 100)  
},
2025-10-31 15:51 负责人:无 分享
已邀请:
2***@qq.com

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

有没有官方人员现身解答一下

要回复问题请先登录注册