How to properly unload/destroy a VIDEO element

后端 未结 15 2152
闹比i
闹比i 2020-12-04 07:58

I\'m working on a realtime media browsing/playback application that uses objects in the browser for playback, when available.

I\'m using a

15条回答
  •  没有蜡笔的小新
    2020-12-04 08:19

    delete(this); 
    

    is not a solution. If it worked for x or y it is a browser misbehaviour. Read here:

    The delete operator removes a property from an object.

    The truth is that some browsers (Firefox for example) will cache in memory the video buffer when autoplay property is on. It is a pain to deal with.

    Removing the video tag from the DOM or pausing it can only produce unstable results. You have to unload the buffer.

    var video = document.getElementById('video-id');
    video.src = "";
    

    My experiment shows that it is done as so but unfortunately this is browser implementation not completely specified by the spec. You do not need to call load() after src change. When changing the src of a video tag you implicitly call a load() on it, this is stated in the W3C spec.

提交回复
热议问题