ExoMedia
ExoMedia copied to clipboard
Recommended way for releasing and recreating the player?
- [X ] I have verified there are no duplicate active or recent bugs, questions, or requests
Include the following:
- ExoMedia version:
4.0.0-preview - Device OS version:
7.0 - Devide Manufacturer:
Google - Device Name:
Emulator
What's the recommended way of releasing the player when the app is going in background and recreating it when it comes into foreground?
The VideoView automatically handles releasing when appropriate (onDetachedFromWindow()) and shouldn't require any additional thought towards onStart/onStop of the parent Fragment or Activity.
The AudioPlayer on the other hand should either be in a Service or be stopped/released in onStop() and created/started in onStart()
Right, but onDetachedFromWindow() only gets called when the layout is being destroyed. This means that the app will continue to keep the player in memory even when it's in background.
I don't see a reason to worry about the memory being used while in the background (in this case) as Android will inform the app of lowMemory or will tell it to destroy itself.
Because Android sends a lowMemory callback only when it's really low in memory. Apps, as good citizens, should not consume memory when they are not being used. Exoplayer also suggests doing the same in its documentation.
It’s important to release the player when it’s no longer needed, so as to free up limited resources such as video decoders for use by other applications. This can be done by calling
ExoPlayer.release.
There are two cases that I see:
- There is no video/audio in playback
- Media playback was paused and the app backgrounded
In the first case we can definitely release the resources used, and this already happens with the stop methods (which are automatically called when playback completes). However with the second case the resources (memory) are still being used to cache the next segment of media for playback, performing a release would cause the media to be reloaded when the app is resumed which is unexpected.
IMHO, the library should not be making this decision for the developer and should atleast let the developer change it :)
The VideoView isn't doing anything that should prevent you from releasing and re-creating it in onStop and onStart; It just doesn't provide cleaner paths to automatically do it for you.
I'm going to update this to a feature request and look in to adding that functionality. (most likely post 4.1.0 though)
Sounds good, thanks!
Is there any good solutions for preventing releasing when play in RecyclerView?
I just found that the VideoView is released after item being scrolled up or down and unvisible for user (the item view was detached from window).
Must i call setReleaseOnDetachFromWindow() for this problem? To be honest, i don't want to cache holders or VideoViews by myself when they are not used or visible. But if i don't do that, i can't find all of them to reease when exiting activity.
Is there any good solutions for preventing releasing when play in RecyclerView? I just found that the VideoView is released after item being scrolled up or down and unvisible for user (the item view was detached from window). Must i call setReleaseOnDetachFromWindow() for this problem? To be honest, i don't want to cache holders or VideoViews by myself when they are not used or visible. But if i don't do that, i can't find all of them to reease when exiting activity.
Same problem, @brianwernick any suggestion to handle this in RecyclerView ?
Guys, if have a different question create a new issue instead of trying to hijack the actual one.
Issue resolved for me, just use onDestroy method to removeVideoApi and invokeStop
@Override protected void onStop() { super.onStop(); Log.d(VideoPlayerActivity.class.getCanonicalName(), "onStop: "); playlistManager.unRegisterPlaylistListener(this); if (videoApi.isPlaying()) { playlistManager.invokePausePlay(); } }
@Override protected void onDestroy() { playlistManager.removeVideoApi(videoApi); playlistManager.invokeStop(); super.onDestroy(); Log.d(VideoPlayerActivity.class.getCanonicalName(), "onDestroy: "); }