Show video inside of a dialog box

All your problems with Audio, Video and Images.

Show video inside of a dialog box

Postby HectorSavage » Mon Sep 07, 2009 2:20 pm

hello,

is it possible to show a video inside of a dialog box(e.g. custom dialog)? i googled a lot about this issue, but couldn't find anything.
does anybody have experience with this?

thank you!
HectorSavage
Freshman
Freshman
 
Posts: 5
Joined: Mon Sep 07, 2009 2:08 pm

Top

Postby AndSmash » Tue Sep 08, 2009 1:29 am

I haven't used MediaPlayer to play video but I think as long as you can define a layout with a MediaPlayer you should be able to do it.

Here is my guess how to go about it.
Within your activity:

Dialog d = new Dialog(this);
d.setContentView(R.layout.your_layout_with_a_media_player);
d.show();

To get a reference to that MediaPlayer:

MediaPlayer mp = (MediaPlayer)d.findViewById(R.id.your_media_player_id);

EDIT: Actually, you can't define a MediaPlayer in a layout so scratch that :(
AndSmash
Freshman
Freshman
 
Posts: 4
Joined: Sat Aug 08, 2009 5:51 am

Postby HectorSavage » Tue Sep 08, 2009 2:55 pm

i found a way to show a video inside of a dialog. but it's still kind of buggy.

the code is quick and dirty, no exception catching etc.
i created a new xml file called videoview. it contains a linearlayout and a videoview.
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.                 Context mContext = (Context) activity; // activity is the main activity
  4.  
  5.                 Dialog dialog = new Dialog(mContext);
  6.  
  7.                 dialog.setTitle("Video");
  8.  
  9.                 dialog.setContentView(R.layout.videoview); // set the layout of the dialog
  10.  
  11.                 VideoView myVideo = (VideoView) dialog.findViewById(R.id.VideoView01);
  12.  
  13.                 myVideo.setVideoPath("/sdcard/video.wmv");
  14.  
  15.  
  16.  
  17.                 MediaController mc = new MediaController(mContext);
  18.  
  19.                 mc.setMediaPlayer(myVideo);
  20.  
  21.                 mc.setAnchorView(myVideo);
  22.  
  23.                 myVideo.setMediaController(mc);
  24.  
  25.                 myVideo.requestFocus();
  26.  
  27.                 myVideo.start();
  28.  
  29.                 dialog.show();
  30.  
  31.  
  32.  
  33.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


ok, video playback works fine, but some problems occured:

1. the mediacontroller is bound to the activity and the dialog "lays over" the activity, so the mc can't be clicked.
i can define own buttons that work like the mediacontroller.
2. the layout of the dialog gets kind of crashed as the videoview resizes its view after scaling the video. picture attached...

suggestions for solving the second problem would be very nice!
Attachments
videoview2.jpg
videoview2.jpg (86.05 KiB) Viewed 1105 times
HectorSavage
Freshman
Freshman
 
Posts: 5
Joined: Mon Sep 07, 2009 2:08 pm

Postby yaj786 » Tue Sep 22, 2009 1:51 am

Why would you do this?

Maybe you should just use a new activity and set the theme to a dialog theme?
yaj786
Developer
Developer
 
Posts: 33
Joined: Fri Jul 10, 2009 7:37 am

Postby HectorSavage » Tue Sep 22, 2009 8:57 am

yaj786 wrote:Why would you do this?

Maybe you should just use a new activity and set the theme to a dialog theme?


because a popup dialog window looks much better than a normal new activity with videoview and might be more user-friendly.
HectorSavage
Freshman
Freshman
 
Posts: 5
Joined: Mon Sep 07, 2009 2:08 pm

Postby yaj786 » Tue Sep 22, 2009 7:51 pm

Yeah your right I suppose.

Either way you can do what I said, it will have all of the features and none of the bugs :) (I think. The resizing of video might still cause a problem, but I doubt it.)
yaj786
Developer
Developer
 
Posts: 33
Joined: Fri Jul 10, 2009 7:37 am

Top

Postby Emmanuel7 » Wed Sep 23, 2009 9:14 pm

Are you sure you have to use a dialog for that ?

Can't you just use any view Widget with the video player inside, and hide it till you don't need it ?
Then you will even be able to use the animations to have it appear in a funky way !
Emmanuel7
Senior Developer
Senior Developer
 
Posts: 164
Joined: Fri Dec 12, 2008 2:17 am
Location: Paris

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 10 guests