changing source on html5 video tag

前端 未结 16 2105
既然无缘
既然无缘 2020-11-22 08:31

i\'m trying to build a video player, that works everywhere. so far i\'d be going with:

16条回答
  •  梦谈多话
    2020-11-22 09:18

    Instead of getting the same video player to load new files, why not erase the entire element and recreate it. Most browsers will automatically load it if the src's are correct.

    Example (using Prototype):

    var vid = new Element('video', { 'autoplay': 'autoplay', 'controls': 'controls' });
    var src = new Element('source', { 'src': 'video.ogg', 'type': 'video/ogg' });
    
    vid.update(src);
    src.insert({ before: new Element('source', { 'src': 'video.mp4', 'type': 'video/mp4' }) });
    
    $('container_div').update(vid);
    

提交回复
热议问题