Assuming you have build your application around the Demo, in the Demo app you have the class ImaPlayer
in package com.google.googlemediaframeworkdemo.demo.adplayer
, which contains two SimpleVideoPlayer
references, and as the name suggests one is for displaying adds and one is for displaying content.
/**
* Plays the ad.
*/
private SimpleVideoPlayer adPlayer;
/**
* Plays the content (i.e. the actual video).
*/
private SimpleVideoPlayer contentPlayer;
For exiting fullscreen you need to call setFullscreen(false) on SimpleVideoPlayer
public void setFullscreen(boolean shouldBeFullscreen)
Make the player enter or leave fullscreen mode.
Parameters:
shouldBeFullscreen - If true, the player is put into fullscreen mode. If false, the player leaves fullscreen mode.
Since both SimpleVideoPlayers are declared private you can not access them. Here are 2 solutions to solve this:
Solution 1:
In ImaPlayer
class create getters for adPlayer
and contentPlayer
public SimpleVideoPlayer getAdPlayer(){
return this.adPlayer;
}
public SimpleVideoPlayer getContentPlayer(){
return this.ContentPlayer;
}
In your MainActivity
where you handle the back key press modify to this
@Override
public void onBackPressed() {
if(isFullScreen) {
imaPlayer.getAdPlayer().setFullscreen(false);
imaPlayer.getContentPlayer().setFullscreen(false);
// after this calls you will see that your callback method onReturnFromFullscreen() will be called
}
else {
super.onBackPressed();
}
}
Solution 2:
In ImaPlayer
class add this code:
public void exitFullscreen(){
if (adPlayer != null) {
adPlayer.setFullscreen(false);
}
contentPlayer.setFullscreen(false);
//again after this calls you will see that your callback method onReturnFromFullscreen() will be called
}
}
In case you have not build it around Demo application you need to call on your video player (which most likely is SimpleVideoPlayer
) setFullscreen(false)