簡體   English   中英

Chrome中的HTML5視頻在mp4下無法正常工作

[英]HTML5 Video in Chrome not working under mp4

我正在一個簡單的網站上在畫布上顯示視頻。 視頻顯示出來,但是只是停留在第一幀,我設置了控件,並且自動播放既不顯示也不播放視頻。

<div style="position: absolute; top: 50px; left: 50px;">

<canvas id="canvasOne" width="500" height="300">
Your browser does not support HTML5 Canvas.
</canvas>
</div>

@section Scripts
{
<script src="@Url.Content("~/Scripts/modernizr-2.5.3.js")" type="text/javascript">        </script>
<script type="text/javascript">
    window.addEventListener('load', eventWindowLoaded, false);
    var firstVideo, secondVideo, videoSource
    var videoDiv;
    function eventWindowLoaded() {
        firstVideo = document.createElement("video");
        videoSource = document.createElement("source");
        firstVideo.appendChild(videoSource);
        //secondVideo = document.createElement("video");
        videoDiv = document.createElement('div');
        document.body.appendChild(videoDiv);
        videoDiv.appendChild(firstVideo);
       //videoDiv.appendChild(secondVideo);
        videoDiv.setAttribute("style", "display:none;");
        var videoType = supportedVideoFormat(firstVideo);       
        if (videoType == "") {
            alert("no video support");
            return;
        }
        videoSource.setAttribute("src", "/Content/QualitySample." + videoType);
        videoSource.setAttribute("type", "video/mp4");
        firstVideo.setAttribute("controls", "controls");
        firstVideo.setAttribute("autoplay", "autoplay");
        firstVideo.addEventListener("canplaythrough", videoLoaded, false);
        //secondVideo.setAttribute("src", "/Content/QualitySample." + videoType);
        //secondVideo.setAttribute("controls", "controls");
        //secondVideo.addEventListener("canplaythrough", videoLoaded, false);


    }

    function supportedVideoFormat(video) {
        var returnExtension = "";
        if (video.canPlayType("video/mp4") == "probably" ||
       video.canPlayType("video/mp4") == "maybe") {
            returnExtension = "mp4";
    } else if (video.canPlayType("video/webm") == "probably" ||
   video.canPlayType("video/webm") == "maybe") {
        returnExtension = "webm";
    } else if (video.canPlayType("video/ogg") == "probably" ||
   video.canPlayType("video/ogg") == "maybe") {
        returnExtension = "ogg";
    }


    return returnExtension;

}

function canvasSupport() {
    return Modernizr.canvas;
}

function videoLoaded(event) {

    canvasApp();

}

function canvasApp() {

    if (!canvasSupport()) {
        return;
    }

    function drawScreen() {

        //Background
        context.fillStyle = '#ffffff';
        context.fillRect(0, 0, theCanvas.width, theCanvas.height);
        //Box
        context.strokeStyle = '#000000';
        context.strokeRect(5, 5, theCanvas.width - 10, theCanvas.height - 10);
        //video
        context.drawImage(firstVideo, 60, 50, 200, 200);
        //context.drawImage(secondVideo, 260, 50, 200, 200);

    }

    var theCanvas = document.getElementById("canvasOne");
    var context = theCanvas.getContext("2d");
    //firstVideo.load();
    firstVideo.play();
    //secondVideo.play();
    setInterval(drawScreen, 33);

}

}當頁面加載時,視頻將顯示在畫布上,並且視頻已加載,但沒有控件處於活動狀態,也無法播放。

MP4是一種媒體文件類型。 但是,MP4可以支持任意數量的不同編解碼器。 某些編解碼器受專利保護,因此Chrome可能無法使用某些編解碼器。 確保視頻的編解碼器受支持。

另請參閱: http : //news.cnet.com/8301-30685_3-20028196-264.html

編輯:我的意思是“受保護”,因為Google不想支付支持編解碼器的費用,而不是Chrome無法處理該編解碼器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM