I want to keep playback in the background when the user decides to press 'home' during the movie.
I followed the guide here: https://developer.android.com/training/tv/playback/options.html
And wrote following code (WHICH WORKS):
@Override
public void onPause() {
super.onPause();
if (mVideoView.isPlaying())
{
// Argument equals true to notify the system that the activity
// wishes to be visible behind other translucent activities
if (! requestVisibleBehind(true)) {
// App-specific method to stop playback and release resources
// because call to requestVisibleBehind(true) failed
stopPlayback();
}
} else {
// Argument equals false because the activity is not playing
requestVisibleBehind(false);
}
}
@Override
public void onVisibleBehindCanceled() {
// App-specific method to stop playback and release resources
stopPlayback();
super.onVisibleBehindCanceled();
}
I've few questions.
I found that commenting out line if (! requestVisibleBehind(true))
doesn't return wanted results. I was quite confused.
- Shouldn't that line return some boolean value? How can it enable background playback? With the debugger, mentioned "if" is successful and it stops the player. Not really sure what's happening and how, so maybe someone can explain me.
requestVisibleBehind() is @deprecated, so is onVisibleBehindCanceled(). Is there any alternatives? When I tried to look into what these functions hold, I also surprised myself when I found (same goes for requestVisibleBehind().
public void onVisibleBehindCanceled() { throw new RuntimeException("Stub!"); }
At one point, I was pretty sure that background playback result is from other actions, but when I comment out code fragmented previously mentioned, I don't get wanted result (which I DO get if I don't comment it).