-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dispose() method removes the video element from HTML #1023
Comments
I second this. |
Can you explain the use case around this more? What scenarios would this be valuable in? |
My use case is a play list where clicking links in play list should update the main video, both source and the poster image. Since poster can not be updated via API method .poster() (due to bug that has been fixed, but not released yet), I decided to destroy the videojs instance, update the src and poster attributes in markup, and then initialize the video.js. I don't want to remove the video element with all classes and data-attributes that sits on it, as then I have to rewrite the whole markup via js every time a play list link is clicked. |
Version 4.4.0 went out yesterday. Would you mind trying that out and seeing if poster() works for you now? |
Have you tried using one of the playlist plugins. Might help out with creating the playlist, specifically. |
That would make sense. The hard part is that in some cases we trash the original element and reconstruct a new one. Like on iPhone where it doesn't like you moving the video element in the dom. The new element is for use in the tech only, and wouldn't have all the original attributes. |
Can't you store a clone of the original element before making changes to the DOM and use it in dispose() method to restore things back to initial state? That's what I ended up doing to resolve my issue. |
Theoretically possible. Would you be willing to create an exploratory PR which provides this functionality via a new API method? |
I support creation of a similar functionality. |
I'd still be interested to know if now that the poster() fix is out, if this is still an issue. But otherwise I think the combination of the poster fix and #1050 should address the use case here. I'm going to close this for now, but if there are other specific use cases for restoring the original html tag I'd be interested to hear them, so please post them here. |
I have a use case that might support this feature.... I have a carousel of "things" (could be a video, could be another carousel of images, could be text) implemented using a 3 div pattern: previous frame, current frame and next frame. The user can see and interact with only the current frame at any given time. The entire carousel of "things" to be viewed may total in the hundreds. As the user swipes through the carousel, previous, current and next are updated to reflect the user's position in a larger storyboard. Imagine a scenario when the 3 divs all contain video tags. Only the current div's video tag needs to be a videojs object. The other 2 are waiting to be turned into videojs objects. The user is free to transition between the 3 divs in either direction. Each time they transition, I create a videojs object to manage playback. When they go next or previous, I'd like to destroy the videojs object to save memory. Suppose the user is watching the current frame's video and decides to navigate forward. In this case, I'd like to call dispose(), but when the user navigates back I can't reconstruct the videojs object because the video tag is no longer in the DOM. I'm injecting a clone of the video tag after destroying as a workaround, but it would be simpler if videojs offered an option to leave the DOM intact. |
I have also similar type of use. |
Another use case into the mix: the responsive site I'm working on uses VideoJS at larger screen sizes but the native player at smaller sizes. The site is designed to bind/unbind behaviours as the breakpoint is crossed (which happens when an iPad is rotated, for instance). Ideally I would init VJS when switching to large layout and uninit it when switching to small. I know I can work around this but it means making an exception to the way all other components on the site are designed and it feels messy. |
@tamlyn rather than init / dispose the player when switching back and forth, would it be easier to turn on / off native controls? |
@gkatsev @mmcc I have similar scenario than described here, where I use videojs as a fallback, but would like to restore the original video element in some cases. It is this still a functionality wanted? If so, I could make a PR that would store the original html element when videojs is initialized, and restore it with a new method in the API, like restore or reset. |
Re-open? This would be nice when switching from say a video (hls) to a |
I can't find any method in the API docs that would allow me to reset changes done by video.js so that DOM would be exactly as it was before video.js is initialized. Usually destroy() method of plugins does so, but all I could find here was a dispose() method which seems to remove the video element from the markup as well. The video element was not inserted by video.js and should remain accessible (via browser's native HTML5 video player) after video.js player is destroyed.
The text was updated successfully, but these errors were encountered: