Android : How to apply custom media controller layout

on Thursday, April 2, 2015


How do I apply custom layout view to MediaController?


I want this layout to applied for my CustomMediaController.



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="4dip"
android:orientation="horizontal">

<ImageButton android:id="@+id/rew"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginStart="24dip"
android:layout_marginLeft="24dip"
android:layout_marginRight="24dip"
android:layout_marginEnd="24dip"
android:background="@drawable/ic_media_remote_back"/>

<ImageButton android:id="@+id/pause"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginStart="24dip"
android:layout_marginLeft="24dip"
android:layout_marginRight="24dip"
android:layout_marginEnd="24dip"
android:background="@drawable/ic_media_pause"/>

<ImageButton android:id="@+id/ffwd"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginStart="24dip"
android:layout_marginLeft="24dip"
android:layout_marginRight="24dip"
android:layout_marginEnd="24dip"
android:background="@drawable/ic_media_remote_forwards"/>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView android:id="@+id/time_current"
android:textSize="14sp"
android:textStyle="bold"
android:paddingTop="4dip"
android:paddingLeft="4dip"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="4dip" />

<SeekBar
android:id="@+id/mediacontroller_progress"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="0dip"
android:layout_weight="0.90"
android:layout_height="32dip"
android:layout_marginTop="10dp"/>

<TextView android:id="@+id/time"
android:textSize="14sp"
android:textStyle="bold"
android:paddingTop="4dip"
android:paddingRight="4dip"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="4dip" />

<ImageButton android:id="@+id/fullscreen"
android:layout_marginTop="12dp"
android:paddingTop="4dip"
android:paddingBottom="4dip"
android:paddingLeft="10dip"
android:paddingRight="4dip"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_media_fullscreen_shrink"
android:layout_marginRight="12dp"
android:layout_marginBottom="12dp" />

</LinearLayout>

</LinearLayout>


custom controller:



public class CustomVideoController extends MediaController {

ImageButton mCCBtn;
Context mContext;
Activity activity;

public CustomVideoController(Context context, Activity activity) {
super(new ContextThemeWrapper(context, R.style.VideoPlayerTheme));
this.activity = activity;
mContext = context;
}

@Override
public void setAnchorView(View view) {
super.setAnchorView(view);
FrameLayout.LayoutParams frameParams = new FrameLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
frameParams.gravity = Gravity.RIGHT | Gravity.TOP;
frameParams.setMargins(12,14,10,12);

View v = AddFullScreenBtn();
addView(v, frameParams);
}

@Override
public void hide() {
super.hide();
}

@Override
public void show(int timeout) {
super.show(0);
}

private View AddFullScreenBtn() {
mCCBtn = new ImageButton(mContext);
mCCBtn.setImageResource(R.drawable.ic_media_fullscreen_shrink);
mCCBtn.setBackgroundColor(Color.WHITE);

mCCBtn.setOnClickListener(new OnClickListener() {


public void onClick(View v) {
Toast.makeText(getContext(), "Fullscreen clicked!", Toast.LENGTH_SHORT).show();
}
});
return mCCBtn;
}
}


The problem is I haven't found any good tutorial for customization exactly VideoView with MediaController. Everyone uses Surfaces and MediaPlayers. Tried it too, but didn't find it as good solution for my particular problem although I have applied custom layouts to them.


All I need is to change background drawables.


0 comments:

Post a Comment