Display a video from a Blob Javascript

后端 未结 2 922
小鲜肉
小鲜肉 2020-12-04 09:23

I would like to display a video from a Javascript Blob/File object in the HTML5 video tag.

This code only works for small videos :

var reader = new          


        
相关标签:
2条回答
  • 2020-12-04 09:24

    I've found. It was so simple that I didnt even see it...

    function display(vid){
    
        var video = document.getElementById("video");
        video.src = window.URL.createObjectURL(vid);
    
    }
    
    0 讨论(0)
  • 2020-12-04 09:33

    In some case blobObject.data should be provided in createObjectURL() method. See this simple trick:

    function playVideo(videoStream){ // as blob 
    
     var video = document.querySelector('video');
    
     var videoUrl=window.URL.createObjectURL(videoStream.data);// blob.data gives actual data
    
     video.src = videoUrl;
    }
    
    0 讨论(0)
提交回复
热议问题