退后退出全屏视频模式 [英] Exit Full Screen Video Mode on Back Press

查看:267
本文介绍了退后退出全屏视频模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用Google提供的 GMF 示例。

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,

这里您可以看到 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();
    }
}


推荐答案

假设您已经在演示应用程序中围绕演示构建了应用程序包 com.google.googlemediaframeworkdemo.demo.adplayer 中的 ImaPlayer ,其中包含两个 SimpleVideoPlayer 引用,顾名思义,一个用于显示添加,一个用于显示内容。

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;


要退出全屏,你需要调用setFullscreen(false)on < a href =http://googleads.github.io/google-media-framework-android/docs/ =nofollow> SimpleVideoPlayer

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.


由于两个SimpleVideoPlayers都被声明为私有,因此无法访问它们。以下是解决此问题的两种解决方案:

Since both SimpleVideoPlayers are declared private you can not access them. Here are 2 solutions to solve this:

解决方案1:

ImaPlayer 类为 adPlayer创建getter contentPlayer

public SimpleVideoPlayer getAdPlayer(){
    return this.adPlayer;
}

public SimpleVideoPlayer getContentPlayer(){
    return this.ContentPlayer;
}

MainActivity 中处理后退键的地方按下修改为

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();
    }
}

解决方案2:

ImaPlayer 类中添加以下代码:

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  
     }
 }

如果您没有围绕演示应用程序构建它,您需要调用您的视频播放器(很可能是 SimpleVideoPlayer setFullscreen(false)

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)

这篇关于退后退出全屏视频模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆