We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
在官方 Demo 中(例如 mesh4DPlayer.js @roamzhen @xxxBW )提供了 createVideoDecoder 的示例代码,但未见关于 createMediaAudioPlayer 的示例。基于文档 [wx.createMediaAudioPlayer](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.createMediaAudioPlayer.html) 的介绍,我尝试将视频与音频同时播放。测试结果显示:
mesh4DPlayer.js
createVideoDecoder
createMediaAudioPlayer
<canvas>
<canvas id="videoCanvas" type="2d" style="width:300px;height:200px;"></canvas>
onReady
wx.createSelectorQuery()
'use strict'; Page({ data: {}, onLoad() {}, onReady() { const query = wx.createSelectorQuery(); query.select("#videoCanvas") .node() .exec((res) => { const canvas = res[0].node; const ctx = canvas.getContext("2d"); const decoder = wx.createVideoDecoder(); const audio = wx.createMediaAudioPlayer(); let started = false; let imageWidth = 1280; let imageHeight = 720; decoder.on('start', () => { started = true; }); decoder.on('stop', () => { console.info('Video decoding stopped'); decoder.seek(0); }); decoder.on('seek', () => { console.log('seek'); }); decoder.on('bufferchange', (info) => { console.log('bufferchange', info); }); decoder.on('ended', () => { console.info('Video ended, restarting...'); }); const loop = () => { if (started) { const frameData = decoder.getFrameData(); if (frameData && frameData.data) { const imageData = ctx.createImageData(imageWidth, imageHeight); imageData.data.set(new Uint8ClampedArray(frameData.data)); ctx.putImageData(imageData, 0, 0); } } canvas.requestAnimationFrame(loop); }; (async () => { try { const decoderResult = await decoder.start({ source: 'https://baikebcs.bdimg.com/baike-other/big-buck-bunny.mp4', mode: 0 }); imageWidth = decoderResult.width; imageHeight = decoderResult.height; console.log('Video decoder started:', decoderResult); const audioResult = await audio.start(); console.log('Audio player started:', audioResult); await audio.addAudioSource(decoder); } catch (error) { console.error('音视频初始化出错:', error); } })(); loop(); }); }, onUnload() {} });
视频与音频均能正常播放,无论是在 Android 还是 iOS 平台。
import createRenderer from './render'; const canvas = wx.createCanvas(); const ctx = canvas.getContext('2d'); const systemInfo = wx.getSystemInfoSync(); const { windowWidth, windowHeight, pixelRatio } = systemInfo; canvas.width = windowWidth * pixelRatio; canvas.height = windowHeight * pixelRatio; const offcanvas = wx.createCanvas(); const decoder = wx.createVideoDecoder(); const audio = wx.createMediaAudioPlayer(); let render; const loop = () => { const frameData = decoder.getFrameData(); console.log('getFrameData', !!frameData); if (frameData) { ctx.clearRect(0, 0, canvas.width, canvas.height); const { width, height, data } = frameData; // 通过渲染函数处理视频数据 render(new Uint8Array(data), width, height); ctx.drawImage(offcanvas, 0, 0, canvas.width, height / width * canvas.width); } requestAnimationFrame(loop); }; decoder.start({ source: 'https://baikebcs.bdimg.com/baike-other/big-buck-bunny.mp4', mode: 0 }).then(data => { wx.setPreferredFramesPerSecond(data.fps); render = createRenderer(offcanvas, data.width, data.height); audio.start().then((res) => { console.log('audio start', res); audio.addAudioSource(decoder).then((res2) => { console.log('audio add', res2); loop(); }); }); });
期待协助排查具体原因并提供修复建议。谢谢!
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Bug 描述
在官方 Demo 中(例如
mesh4DPlayer.js
@roamzhen @xxxBW )提供了createVideoDecoder
的示例代码,但未见关于createMediaAudioPlayer
的示例。基于文档 [wx.createMediaAudioPlayer](https://developers.weixin.qq.com/miniprogram/dev/api/media/audio/wx.createMediaAudioPlayer.html) 的介绍,我尝试将视频与音频同时播放。测试结果显示:重现步骤
<canvas>
标签用于视频显示:onReady
生命周期中,通过wx.createSelectorQuery()
获取 Canvas 节点,并初始化视频解码器和音频播放器:预期结果
视频与音频均能正常播放,无论是在 Android 还是 iOS 平台。
实际结果
其他提示
期待协助排查具体原因并提供修复建议。谢谢!
The text was updated successfully, but these errors were encountered: