How to properly unload/destroy a VIDEO element

后端 未结 15 2123
闹比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:40

    It is very tricky to dispose video from the DOM structure. It may lead to browser crashing. Here is the solution that helped me in my project.

    var videoElement = document.getElementById('id_of_the_video_element_here');
    videoElement.pause();
    videoElement.removeAttribute('src'); // empty source
    videoElement.load();
    

    this will reset everything, silent without errors !

    Edit: Here are the full details as recommended in the Standard: https://html.spec.whatwg.org/multipage/media.html#best-practices-for-authors-using-media-elements

    Hope it resolve your query.

提交回复
热议问题