Exit Full Screen Video Mode on Back Press
Asked Answered
C

1

2

I just started with this GMF example provided by Google.

I would like to know How can I Exit Full Screen Video Mode by doing tap on back button, I tried using below code, but did not get any success,

here you can see the actual code of MainActivity.java

boolean isFullScreen = false; // globally declared

@Override
public void onGoToFullscreen() {
    isFullScreen = true;
    videoListView.setVisibility(View.INVISIBLE);
}

@Override
public void onReturnFromFullscreen() {
    videoListView.setVisibility(View.VISIBLE);
}

@Override
public void onBackPressed() {
    if(isFullScreen) {
        onReturnFromFullscreen();
    }
    else {
        super.onBackPressed();
    }
}
Connote answered 11/3, 2016 at 5:59 Comment(1)
what problem you are facing exactly. ?Telemark
F
2

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)

Footed answered 16/3, 2016 at 12:37 Comment(3)
Have a look at this issue, please : #36056495Connote
@Connote I have responded there to your question.Footed
check this please: #36098817Connote

© 2022 - 2024 — McMap. All rights reserved.