想做这样一个技术流程:将视频用WebView播放,然后渲染到Canvas上;通过Java的SurfaceView去得到textureid;然后提供给Unity使用。
如何把WebView的视频渲染到Canvas上呢,这里提供了一个h5的代码:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
window.addEventListener('load', eventWindowLoaded, false);
var videoElement;
var videoDiv;
function eventWindowLoaded()
{
videoElement = document.getElementById("video");
videoElement.addEventListener("canplaythrough",videoLoaded,false);
}
function videoLoaded(event)
{
canvasApp();
}
function canvasApp()
{
function drawScreen ()
{
//Background
context.fillStyle = '#ffffaa';
context.fillRect(0, 0, theCanvas.width, theCanvas.height);
//Box
context.strokeStyle = '#000000';
context.strokeRect(5, 5, theCanvas.width-10, theCanvas.height-10);
//video