我设计了我的应用程序以全屏模式工作。没有状态栏和操作栏可见。这假设是一个问题,因为每次加载来自youtube的视频都会显示YoutubeAndroidPlayerAPI的状态栏。
我的活动:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.activity_open_translate,R.anim.activity_close_scale);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
if(getActionBar()!=null) {
ActionBar actionBar = getActionBar();
actionBar.hide();
}
setContentView(R.layout.activity_fad_socios);
...
}
...
private void changeFragment(int index) {
switch(index) {
case 0:{
getSupportFragmentManager().beginTransaction().replace(R.id.fragmentContainer, new FADFragment(),"informacion").commit();
break;
}
...
}
我在片段中引用YoutubeAPI的方式:
fragmentManager = getActivity().getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragment = new YouTubePlayerSupportFragment();
fragmentTransaction.add(R.id.fragmentz, fragment);
fragmentTransaction.commit();
portadaFrag.setVisibility(View.GONE);
if(buttonSelected == 0) {
((FADSociosActivity) getActivity()).playingYoutube=true;
fragment.initialize(getActivity().getResources().getString(R.string.youKEY), new OnInitializedListener(){
@Override
public void onInitializationFailure(Provider arg0, YouTubeInitializationResult arg1) {
Log.e("fail","fail");
}
@Override
public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1, boolean arg2) {
youtubePlayer = arg1;
youtubePlayer.loadVideo("-D-MVgOvvOo");
youtubePlayer.setPlaybackEventListener(new PlaybackEventListener() {
@Override
public void onBuffering(boolean arg0) {
try {
((FADSociosActivity) getActivity()).refreshWindow();
}
catch(Exception e) {}
}
@Override
public void onPaused() {
try {
((FADSociosActivity) getActivity()).playingYoutube=false;
((FADSociosActivity) getActivity()).refreshWindow();
}
catch(Exception e) {}
}
@Override
public void onPlaying() {
try {
youtubePlayButton.setVisibility(View.GONE);
((FADSociosActivity) getActivity()).playingYoutube=true;
((FADSociosActivity) getActivity()).refreshWindow();
}
catch(Exception e) {}
}
@Override
public void onSeekTo(int arg0) {
try {
((FADSociosActivity) getActivity()).refreshWindow();
}
catch(Exception e) {}
}
@Override
public void onStopped() {
try {
youtubePlayButton.setVisibility(View.VISIBLE);
((FADSociosActivity) getActivity()).playingYoutube=false;
((FADSociosActivity) getActivity()).refreshWindow();
}
catch(Exception e) {}
}
});
我在第一个活动中的refreshWindow方法:
public void refreshWindow() {
try {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
getWindow().getDecorView().findViewById(android.R.id.content).invalidate();
}
catch(Exception e) {
e.printStackTrace();
}
}
使用此方法可以在状态栏稍微不合需要的倾斜后再次强制活动处于全屏模式。无论如何,每当用户点击视频时,活动退出全屏模式。似乎YoutubePlayer-API覆盖了我的FLAG_FULLSCREEN,我无法避免这种情况。谁知道如何克服这个?提前谢谢。
答案 0 :(得分:1)
好吧,初始化后设置标志YouTubePlayer.FULLSCREEN_FLAG_CONTROL_ORIENTATION似乎解决了问题=)
答案 1 :(得分:1)
在我的情况下,我必须重置onInitializationSuccess中的所有标志,从不显示状态栏:
player.setFullscreenControlFlags(-1);