I want to display VideoView
in DialogFragment
. Now, I am facing two problems:
- VideoView is showing darker video:
Reason is VideoView is drawn behind the dialog's Window. I applied,
mVideoView.setZOrderOnTop(true);
But no success, it displayed white color in place of VideoView. For this, I referred this SO question.
- Even media controllers are hiding behind the window. There's no way i can touch and bring the media controllers back to visible. I didn't found any way to make this run.
Anyone can please make this work or suggest any workaround..?
Code in onViewCreated()
:
mMediaController = new MediaController(getActivity());
mMediaController.setAnchorView(mVideoView);
Uri video = Uri.parse(videoDetailByIdResponse.getData().getVideoFile());
mVideoView.setMediaController(mMediaController);
mVideoView.setVideoURI(video);
mVideoView.requestFocus();
//mVideoView.setZOrderOnTop(true);
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mMediaController.show();
mVideoView.start();
}
});
mVideoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
return false;
}
});
mVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
}
});
layout_dialog_fragment.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical">
<VideoView
android:id="@+id/vv_video_preview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/colorPrimary"
android:layout_weight="1"
android:layout_gravity="center_horizontal" />
<com.idolbee.android.customview.CustomTextView
android:id="@+id/tv_user_profile_dialog_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:padding="@dimen/padding_16"
tools:text="My live performance at Sydney" />
<!--Footer-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/padding_16">
<com.idolbee.android.customview.CustomTextView
android:id="@+id/tv_user_profile_dialog_stings_and_comments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_sting_comment"
android:drawablePadding="@dimen/padding_8"
android:gravity="center"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
tools:text="@string/_1020_stings_210_comments" />
<Space
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<ImageView
android:id="@+id/tv_user_profile_dialog_spam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="@dimen/margin_4"
android:src="@drawable/ic_report" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent">
<com.idolbee.android.customview.CustomTextView
android:id="@+id/tv_user_profile_dialog_sting"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="@dimen/padding_8"
android:drawableTop="@drawable/ic_sting_off"
android:gravity="center"
android:padding="@dimen/padding_8"
android:text="@string/list_item_home_sting" />
<com.idolbee.android.customview.CustomTextView
android:id="@+id/tv_user_profile_dialog_comment"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="@dimen/padding_8"
android:drawableTop="@drawable/ic_comments"
android:gravity="center"
android:padding="@dimen/padding_8"
android:text="@string/list_item_home_comment" />
<com.idolbee.android.customview.CustomTextView
android:id="@+id/tv_user_profile_dialog_share"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="@dimen/padding_8"
android:drawableTop="@drawable/ic_share"
android:gravity="center"
android:padding="@dimen/padding_8"
android:text="@string/list_item_home_share" />
<com.idolbee.android.customview.CustomTextView
android:id="@+id/tv_user_profile_dialog_chat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawablePadding="@dimen/padding_8"
android:drawableTop="@drawable/ic_chat"
android:gravity="center"
android:padding="@dimen/padding_8"
android:text="@string/list_item_home_chat" />
</LinearLayout>
</LinearLayout>