views:

35

answers:

1

Hi all! I am using the default Android Media Player in an Activity, trying to play back a couple of video files. However I have a problem with programming what I want. The desired program outcome would be the following:

  • A video file is played back
  • After that, a dialog is shown, asking the user something
  • A pause of 5 seconds occurs
  • The next video is shown
  • and so forth

How am I to program this? Currently, I use a paradigm like the following:

  • I have a method that sets up the player for the a file, e.g. playVideo(int) So I pass it the first file.
  • When the player is prepared, it will be started in onPrepared(MediaPlayer).
  • When the video is finished, the onCompletion(MediaPlayer) listener of the media player shows the dialog to the user by calling showDialog().
  • The user accepts the dialog. Before calling dismiss() on the dialog, the player object is started for the next file by calling playVideo(int).

This works, but it feels a bit quirky and not clean. And it's of course very procedural. The problems are:

  • that I can't figure out how to insert a pause after the dialog is dismissed.
  • that I maybe want to change the presentation order of dialogs and videos and this ain't too easy now

Has anyone got an idea?

A: 

For the pause, you could use the AlarmManager to schedule an alarm five seconds from now. It will launch an intent, and that intent could call playVideo(int).

Ron Romero
Thanks, however I am doing everything within one Activity now. A new Intent would mean launching a new Activity, is that right? So, summing up: This means I'd have to show only one video per Activity launch, at the `onCompletion` of the video show the dialog, and at the `dismiss()` of the dialog launch a new (delayed) Intent. Is that what you thought of?
slhck