【发布时间】:2020-10-17 12:39:15
【问题描述】:
我尝试在带有 Html5 和 Javascript 的三星 SmartTV (2017) 的画布上显示视频(电视扩展 3.0)。
这是我的示例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<style>
body {
font: white
}
</style>
<body>
<!-- <video width="820" height="240" controls>
<source src="https://www.quirksmode.org/html5/videos/big_buck_bunny.ogv">
</video> -->
<video id="source" src="https://www.radiantmediaplayer.com/media/big-buck-bunny-360p.mp4" autoplay muted
controls></video>
<hr>
<canvas id="c1"></canvas>
<canvas id="c2"></canvas>
<canvas id="c3"></canvas>
<canvas id="c4"></canvas>
</body>
<script>
var video = $('#source')[0]; //variable to tie to our source
//create an array to store our canvases
// var splitCanvas = [$('#c1')[0], $('#c2')[0], $('#c3')[0], $('#c4')[0]];
var splitCanvas = [$('#c1')[0], $('#c2')[0]];
//start the function once the video starts playing
video.addEventListener('playing', function () {
//create some variables for readability
//halving the width and height results in 4 quadrants
var w = video.videoWidth / 2;
var h = video.videoHeight;
//create a canvas context so we can manipulate the images
var context = [];
for (var x = 0; x < splitCanvas
.length; x++) { //set the canvas dimensions to the native size of the video
splitCanvas[x].width = w;
splitCanvas[x].height = h;
context.push(splitCanvas[x].getContext('2d')); //create the context
};
console.log('drawing'); //Draw the 4 quadrants from the source video every 33 ms (approx 30 FPS)
setInterval(function () { //context.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); //Upper left
context[0].drawImage(video, 0, 0, w, h, 0, 0, w,
h
);
context[1].drawImage(video,
w, 0, //x, y start clipping
w, h, //x, y clipping width
0, 0, //x, y placement
w, h); //width, height of placement
}, 33);
});
</script>
</html>
在模拟器和 Chrome 上,它在 chrome devtool 中正常工作:
在我的电视上,视频正在播放,但在 Chrome Devtool 上,画布是空白且没有错误:
这对我来说很奇怪,因为所有测试都是相同的,视频显示但画布每次都是空的。
我怀疑 DrawImage,如果我在控制台中没有任何错误,并且在 drawImage 中添加断点时,它会正常继续,如何找出问题所在。
在画布上显示视频有什么想法或等效的吗?
【问题讨论】:
-
尝试各种视频格式+编解码器。以前用mp4的时候安卓也有过这样的bug,可能是同一种问题。
-
尝试下载资产并将其放入应用文件夹中。可能存在由 file:// 协议引起的跨域问题。
-
@Kaiido,测试了多种格式+编解码器,结果都是一样的。我会尝试使用本地视频来检查是否有效,谢谢
标签: javascript html tizen tizen-web-app tizen-emulator