2015-11-03 103 views
0

我使用HTML5画布拍摄视频标签的屏幕截图。这大约80%的时间在Chrome上运行。其他20%的时间我得到“无法执行'toDataURL''HTMLCanvasElement':受污染的画布可能无法导出”错误。我假设这是因为视频源不支持CORS。如何判断HTML5视频标签源是否支持CORS?

我试过添加属性'videoTag.attr('crossorigin','anonymous');'到视频标签,但这似乎没有帮助。

所以我的问题是有无论如何告诉视频标签是否支持CORS?

// Get handles on the video element 
    var video = videoContainer[0]; 

    var canvas = jQuery('#temp-canvas')[0]; 
    var context = canvas.getContext('2d'); 

    canvas.width = 640; 
    canvas.height = 360; 

    // Define the size of the rectangle that will be filled (basically the entire element) 
    context.fillRect(0, 0, 640, 390); 

    // Grab the image from the video 
    context.drawImage(video, 0, 0, canvas.width, canvas.height); 

    //return the url so we can use it 
    //Failed to execute toDataURL exception thrown here 
    imageUrl = canvas.toDataURL(); 
+0

我想我确实记得视频上的这个错误有关要绘制的文件格式(类似于DR4在mp4中)有些事情不确定,但现在无法对其进行搜索...... – Kaiido

回答

1

由于您正在测试错误情况而不是浏览器功能,因此可以使用try-catch块。