Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play video in dialog box android

I want to play a video in a dialog box which appears when an image is clicked. The video does not play and the app crashes. Here is my code:

image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.introvid);
dialog.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.copyFrom(dialog.getWindow().getAttributes());
dialog.getWindow().setAttributes(lp);
final VideoView videoview = (VideoView) findViewById(R.id.surface_view);
Uri uri = Uri.parse("android.resource://"+getPackageName()+"/"+R.raw.introvideo);
videoview.setVideoURI(uri);
videoview.start();
}
});

my video is in the res/raw folder. Its an MP4 video.

like image 291
Shahbaz Pothiawala Avatar asked Sep 25 '13 07:09

Shahbaz Pothiawala


People also ask

How to display dialog Fragment Android?

Showing the DialogFragment It is not necessary to manually create a FragmentTransaction to display your DialogFragment . Instead, use the show() method to display your dialog. You can pass a reference to a FragmentManager and a String to use as a FragmentTransaction tag.

What is AlertDialog in Android?

Android AlertDialog can be used to display the dialog message with OK and Cancel buttons. It can be used to interrupt and ask the user about his/her choice to continue or discontinue. Android AlertDialog is composed of three regions: title, content area and action buttons.

What is dialog Fragment?

Android DialogFragments. DialogFragment is a utility class which extends the Fragment class. It is a part of the v4 support library and is used to display an overlay modal window within an activity that floats on top of the rest of the content. Essentially a DialogFragment displays a Dialog but inside a Fragment.


1 Answers

Try this, Add this code in your code. I hope it will solve the problem

final VideoView videoview = (VideoView) dialog.findViewById(R.id.surface_view);
like image 76
Murali Ganesan Avatar answered Nov 02 '22 17:11

Murali Ganesan