Android : Change MediaController position on rotation

on Tuesday, April 7, 2015


I'm trying to change MediaController's anchor dynamically on orientation changes. And after all my attemts this isn't working as needed.


Perhabs you could point me my mistake.


In few words:


Portrait mode:



  1. weightSum = 1.

  2. SurfaceView weight: 0.4

  3. MediaController and HorizontalScrollView weight: 0.6

  4. MediaController always visible and not hiding


Landscape mode:




  1. SurfaceView weight: 0.0 (full screen)




  2. MediaControlls = View.Gone (I need to change its anchor to SurfaceView. And popup onTouch. But how??)






CODE CODE:


player.xml:



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
tools:context="tenkol.design.com.imbrecords.ActivityExoPlayer"
android:weightSum="1"
android:orientation="vertical">

<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/surface_wrapper"
android:layout_weight="0.4">

<com.google.android.exoplayer.VideoSurfaceView
android:id="@+id/surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />

<View
android:id="@+id/shutter"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black" />
</FrameLayout>

<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.6"
android:orientation="vertical">

<FrameLayout
android:id="@+id/controls_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp">
</FrameLayout>

<HorizontalScrollView
android:id="@+id/myGallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp">

<LinearLayout
android:id="@+id/channelsScrollView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingTop="5dp"
/>
</HorizontalScrollView>

</LinearLayout>

</LinearLayout>


code with transformation:



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

if (Global.getScreenOrientation(this) == Configuration.ORIENTATION_LANDSCAPE) {
//hide action bar
getSupportActionBar().hide();
if (myGallery != null) {
//hide HorizontalScrollView
myGallery.setVisibility(View.GONE);
}
//make surface fullscreen
surfaceWrapper.setLayoutParams(new LinearLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT, 0f));
controlsWrapper.setLayoutParams(new LinearLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT, 0f));
//hide mediaController
mc.hide();
controlsWrapper.setVisibility(View.GONE);
}
if (Global.getScreenOrientation(this) == Configuration.ORIENTATION_PORTRAIT) {
//and here restore everything
getSupportActionBar().show();
if (myGallery != null) {
myGallery.setVisibility(View.VISIBLE);
}

surfaceWrapper.setLayoutParams(new LinearLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT, 0.4f));
controlsWrapper.setLayoutParams(new LinearLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT, 0.6f));
controlsWrapper.setVisibility(View.VISIBLE);
}
}


What I tried:


1) When Landscape: create another mediaController and bind to root view(doesnt work):



mediaController.setAnchorView(root);
mediaController.setMediaPlayer(player.getPlayerControl());
mediaController.setEnabled(true);
mediaController.show(3);


2) When Landscape: change the anchor of previous MediaController (Nah).



mc.setAnchorView(surfaceWrapper);
mc.show(3);


So how can I change the MediaController's anchor to SurfaceView dynamically in LANDSCAPE mode?


Maybe someone faced such problem already. Please give me a hint or solution. Appreciate any help. Really confused with it already..


P.S. Tell if some more code needed.


0 comments:

Post a Comment