Exit Full Screen Video Mode on Back Press

拈花ヽ惹草 提交于 2019-12-06 07:20:32

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)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!