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 callingshowDialog()
. - The user accepts the dialog. Before calling
dismiss()
on the dialog, the player object is started for the next file by callingplayVideo(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?
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)
.
精彩评论