显示全屏幕片段内定义的视频

时间:2015-06-15 16:20:58

标签: android android-fragments android-framelayout android-video-player android-videoview

我有一个活动有两个framelayout,被两个片段取代。一个拥有视频播放器(使用videoView),另一个拥有视频列表。如下所示

video_player_activity.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/normal_margin"
android:paddingTop="@dimen/normal_margin"

tools:context="com.example.project.android.VideoPlayerActivity">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:id="@+id/rl_video_player_relativi_layout"
    android:orientation="vertical">

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="top"
        android:id="@+id/fl_player_activity_video_surfrace_container"
        >
    </FrameLayout>


</RelativeLayout>

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/rl_video_player_relativi_layout"
    android:layout_marginTop="10dp"
    android:id="@+id/fl_player_activity_video_list_container"
    ></FrameLayout>

VideoPlayerActivity.java

public class VideoPlayerActivity extends ActionBarActivity {

VideoPlayerFragment videoPlayerFragment;
VideoListFragment videoListFragment;
FragmentTransaction fragmentTransaction;
Bundle intentBundle;
private String videoUrl;
private CommonFunctions commonFunctions;
private String videoSubject;
private  String videoLevel;
private Context context;
private int oldOptions;
private FrameLayout flVideoSurface;
RelativeLayout.LayoutParams fllp;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_video_player);

    intentBundle = getIntent().getExtras();
   /* videoUrl = intentBundle.getString(projectGlobal.videoUrl);
    videoSubject= intentBundle.getString(projectGlobal.videoSubject);
    videoLevel = intentBundle.getString(projectGlobal.videoLevel);*/
    context=this;

    flVideoSurface=(FrameLayout) findViewById(R.id.fl_player_activity_video_surfrace_container);

    fllp = new RelativeLayout.LayoutParams(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    //Log.d("video url ", videoUrl);

    videoPlayerFragment = new VideoPlayerFragment();
    videoPlayerFragment.setArguments(intentBundle);

    fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.fl_player_activity_video_surfrace_container, videoPlayerFragment);
    fragmentTransaction.commit();



     intentBundle.putString(projectGlobal.listBy,     projectGlobal.mostViewed);
    videoListFragment=new VideoListFragment();
    videoListFragment.setArguments(intentBundle);

    fragmentTransaction=getFragmentManager().beginTransaction();
    fragmentTransaction.replace(R.id.fl_player_activity_video_list_container, videoListFragment);
    fragmentTransaction.commit();
    Log.d("second commit", "end");



}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_video_player, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    super.onConfigurationChanged(newConfig);

    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
    {
        fragmentTransaction= getFragmentManager().beginTransaction();
        fragmentTransaction.hide(videoListFragment);
        fragmentTransaction.commit();
        flVideoSurface.setLayoutParams(fllp);
        flVideoSurface.forceLayout();


       // projectGlobal.playerActivityVideoSurface.setDimensions(720,1184);
        /*oldOptions = getWindow().getDecorView().getSystemUiVisibility();
        int newOptions = oldOptions;
        newOptions &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
        newOptions |= View.SYSTEM_UI_FLAG_FULLSCREEN;
        newOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
        newOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE;
        newOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
        getWindow().getDecorView().setSystemUiVisibility(newOptions);
        getSupportActionBar().hide();*/
    }
    else
    {
        fragmentTransaction=getFragmentManager().beginTransaction();
        fragmentTransaction.show(videoListFragment);
        fragmentTransaction.commit();
        /*getWindow().getDecorView().setSystemUiVisibility(oldOptions);
        getSupportActionBar().show();*/
    }
}
}

我能够使用fragmentTransaction将这两个片段带入活动。问题是当我尝试使用控件的全屏按钮全屏显示视频表面时,或者在横向显示时它不会全屏显示。 下面是我在VideoPlayerFragment.java中使用的代码,以使视图全屏显示

   displayMetrics = new DisplayMetrics();
  getActivity().getWindowManager().getDefaultDisplay().
  getMetrics(displayMetrics);
   fullScreenWidth=displayMetrics.widthPixels;
   fullScreenHeight=displayMetrics.heightPixels;

  @Override
     public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
        Log.d("config changed  to ","landscapte");
        videoSurface.setDimensions(fullScreenHeight,fullScreenWidth);
        isOrientationPortrat=false;
        isFullScreen = true;


    } else {
        Log.d("config changed to ","portrait");
        isOrientationPortrat=true;

    }
}

任何人都可以帮忙......!提前谢谢!

0 个答案:

没有答案