用randerjs截取视频第一帧时,安卓没啥问题,ios只要一打开autoplay:true就自己弹出来播放视频了,不打开autoplay的话截出来是个白色空白
let video = document.createElement('video')
video.muted = true
video.autoplay = false
video.setAttribute('width', res.width)
video.setAttribute('height', res.height)
video.setAttribute('preload', 'auto')
video.setAttribute('crossOrigin', 'anonymous')
video.setAttribute('src', res.filePath)
video.addEventListener('loadeddata', function() {
let canvas = document.createElement('canvas')
let width = video.width
let height = video.height
canvas.width = width
canvas.height = height
canvas.getContext('2d').drawImage(video, 0, 0, width, height) // 绘制canvas
const dataURL = canvas.toDataURL('image/jpeg') // 转换为base64
// 传递数据给逻辑层
ownerInstance.callMethod('getDataURL', {
dataURL: dataURL
})
})
video.addEventListener('error', err => {
console.log('视频加载失败', err)
})
1***@qq.com (作者)
放弃了,用默认图了
2024-08-27 14:03