return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - Change Video source to blobObjectURL - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Change Video source to blobObjectURL - Stack Overflow

programmeradmin0浏览0评论

I would like to hide a video source's attribute. Therefore I wanted to convert the src attribute of the video's source-tag into an objectURL. It sadly doesn't work.

I already tried

function display(vid){
    var video = document.getElementById("video");
    video.src = window.URL.createObjectURL(vid);
}

display('video.mp4');

(as provided here: Display a video from a Blob Javascript)

That did not work and the Stack is already 5 years old.

HTML Looks like this

<video id="video">
   <source type="video/mp4" src="video.mp4">
</video>

I would like to hide a video source's attribute. Therefore I wanted to convert the src attribute of the video's source-tag into an objectURL. It sadly doesn't work.

I already tried

function display(vid){
    var video = document.getElementById("video");
    video.src = window.URL.createObjectURL(vid);
}

display('video.mp4');

(as provided here: Display a video from a Blob Javascript)

That did not work and the Stack is already 5 years old.

HTML Looks like this

<video id="video">
   <source type="video/mp4" src="video.mp4">
</video>
Share Improve this question asked Dec 27, 2018 at 21:02 MikeMike 5525 silver badges14 bronze badges 3
  • You have to pass a blob to the display function in that example, not just a string. – Herohtar Commented Dec 27, 2018 at 21:06
  • You can convert a URL to a blob asynchronously using the fetch API response.toBlob() method. – Patrick Roberts Commented Dec 27, 2018 at 21:13
  • have a look at this answer which loads the video into a blob and then to the page - stackoverflow./questions/18251632/… - but note that if you're loading the video at all, there will be a network call that references your original source that people can find no matter how much you obfuscate the javascript... – Offbeatmammal Commented Dec 27, 2018 at 22:11
Add a ment  | 

2 Answers 2

Reset to default 8

Change the src attribute at the video element directly to the new blob URL.


An example that worked for me:

HTML:

<video width="320" height="240" controls></video>

JS:

function changeVideoSource(blob, videoElement) {
  var blobUrl = URL.createObjectURL(blob);
  console.log(`Changing video source to blob URL "${blobUrl}"`)
  videoElement.src = blobUrl;
  videoElement.play();
}

function fetchVideo(url) {
  return fetch(url).then(function(response) {        
    return response.blob();
  });
}

fetchVideo('https://wherever./video.mp4').then(function(blob) {
  changeVideoSource(blob, video);
});

Current code looks like this

function blobClip(obj){
   var video = obj;
   var sources = video.getElementsByTagName('source');
   var newReq = new Request(sources[0].src);
   fetch(newReq)
   .then(function(response) {        
        return response.blob();
   })
   .then(function(myBlob) {
        var objectURL = URL.createObjectURL(myBlob);
        sources[0].src = objectURL;
   });
}

That did not really work. I also tried adding video.load() after the source[0].src got its new objectURL.

Im pretty sure the function call maybe wrong: I added onloadeddata="blobClip(this);" to the video tag. I also tried onload with no success.

发布评论

评论列表(0)

  1. 暂无评论