custom video Controller xml view, does not fill up the entire view (surfaceviewholder)



I'm trying to make my video controller to use that with surfaceView and MediaPlayer to show video in my apps.


Now I'm using of this xml view:



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<RelativeLayout
android:id="@+id/toppanel"
style="@style/toppanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" >

<ImageButton
android:id="@+id/pause"
style="@style/playpausebtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:layout_margin="8dp"
android:contentDescription="@string/description" />

<ImageButton
android:id="@+id/report"
style="@style/reportbtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_margin="8dp"
android:contentDescription="@string/description"
android:src="@drawable/ic_report"
android:background="@drawable/parsvid_background_tab" />

<ImageButton
android:id="@+id/share"
style="@style/reportbtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toLeftOf="@+id/report"
android:layout_margin="8dp"
android:contentDescription="@string/description"
android:src="@drawable/ic_share"
android:background="@drawable/parsvid_background_tab" />

</RelativeLayout>

<LinearLayout
android:id="@+id/controlholder"
style="@style/bottompanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:paddingBottom="4dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingTop="8dp" >

<TextView
android:id="@+id/time_current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="4dp"
android:contentDescription="@string/description"
android:text="00:00"
android:textColor="#F2408ed6" />

<SeekBar
android:id="@+id/mediacontroller_progress"
style="@style/playerSeekbar"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:contentDescription="@string/description" />

<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:contentDescription="@string/description"
android:text="00:00"
android:textColor="#F2ffffff" />

<ImageButton
android:id="@+id/fullscreen"
style="@style/reportbtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:contentDescription="@string/description"
android:src="@drawable/ic_media_fullscreen"
android:background="@drawable/parsvid_background_tab"/>
</LinearLayout>

</RelativeLayout>


It's work properly and fill up entire view, even in fullscreen mode.


But now I want to put paly/pause button to the middle of screen, then I changed the xml file to this:



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://ift.tt/nIICcg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<RelativeLayout
android:id="@+id/toppanel"
style="@style/toppanel"
android:layout_width="match_parent"
android:layout_height="66dp">

<ImageButton
android:id="@+id/report"
style="@style/reportbtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:layout_margin="8dp"
android:background="@drawable/parsvid_background_tab"
android:contentDescription="@string/description"
android:src="@drawable/ic_report" />

<ImageButton
android:id="@+id/share"
style="@style/reportbtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_centerHorizontal="true"
android:layout_margin="8dp"
android:background="@drawable/parsvid_background_tab"
android:contentDescription="@string/description"
android:src="@drawable/ic_share" />
</RelativeLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal" >

<ImageButton
android:id="@+id/pause"
style="@style/playpausebtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_margin="8dp"
android:contentDescription="@string/description" />

</LinearLayout>

<LinearLayout
android:id="@+id/controlholder"
style="@style/bottompanel"
android:layout_width="match_parent"
android:layout_height="66dp"
android:orientation="horizontal"
android:paddingBottom="4dp"
android:paddingLeft="6dp"
android:paddingRight="6dp"
android:paddingTop="8dp" >

<TextView
android:id="@+id/time_current"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="4dp"
android:contentDescription="@string/description"
android:text="00:00"
android:textColor="#F2408ed6" />

<SeekBar
android:id="@+id/mediacontroller_progress"
style="@style/playerSeekbar"
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="4dp"
android:layout_weight="1"
android:contentDescription="@string/description" />

<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:contentDescription="@string/description"
android:text="00:00"
android:textColor="#F2ffffff" />

<ImageButton
android:id="@+id/fullscreen"
style="@style/reportbtn"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/parsvid_background_tab"
android:contentDescription="@string/description"
android:src="@drawable/ic_media_fullscreen" />

</LinearLayout>

</LinearLayout>


But! new xml, does not fill entire view and I get something like you can see in attached image.


enter image description here


For better understanding, I show some snippets of my code: In first step I get with of window and then set the height based on that:



DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
fWidth = displayMetrics.widthPixels;
fHeight = ( fWidth / 2 ) + 67;


Then in SurfaceCreated method I assing them to my sirfaceviewHolder:



params = new LinearLayout.LayoutParams(fWidth, fHeight);
mVideoSurfaceHodler.setLayoutParams(params);
mPlayer.setDisplay(holder);


And finally in onPrepared method I set surfaceviewholder as anchorview for my custom controller:



mMediaPlayerIsPrepared = true;
duration = mPlayer.getDuration();
mController.setMediaPlayer(this);
mController.setAnchorView(mVideoSurfaceHodler);
mController.show();
enableRotation(this);
mPlayer.start();

No comments:

Post a Comment