Adding sources to HTML5 video in javascript?

后端 未结 1 1693
时光说笑
时光说笑 2021-02-04 03:38

I am running the following code for html5 video.

var media;
function videotr(){
  media = document.createElement(\'video\');
  media.preload = true;
  media.id =         


        
相关标签:
1条回答
  • 2021-02-04 04:29

    Create a new source element and append it to the video element:

    function addSourceToVideo(element, src, type) {
        var source = document.createElement('source');
    
        source.src = src;
        source.type = type;
    
        element.appendChild(source);
    }
    
    var video = document.createElement('video');
    
    document.body.appendChild(video);
    
    addSourceToVideo(video, 'http://upload.wikimedia.org/wikipedia/commons/7/79/Big_Buck_Bunny_small.ogv', 'video/ogg');
    
    video.play();
    

    Here's a fiddle for it.

    0 讨论(0)
提交回复
热议问题