When you use the image library player that comes with Google to play a video, you can pause the playback of the music player that comes with Google.
The solution is to send the music pause broadcast when you start the image library player to play the video. After music receives the broadcast, it pause playing the music. Code processing is as follows:
1. The image library player sends music paused broadcasts.
When playing a video, the movieviewcontrol. Java file's movieviewcontrol constructor sends a pause music broadcast.
The movieviewcontrol. Java file is located in the packages \ apps \ gallery3d \ SRC \ com \ cooliris \ Media Directory.
(1) Parameter definition:
// Copied from MediaPlaybackService in the Music Player app. Should be // public, but isn't. private static final String SERVICECMD = "com.android.music.musicservicecommand"; private static final String CMDNAME = "command"; private static final String CMDPAUSE = "pause";
(2) Send Broadcast
Intent I = new intent (servicecmd); I. putextra (pause name, pause); // broadcast context. sendbroadcast (I );
2. Music receives pause Broadcast
The code of the broadcast sent when the music player receives the video is located in the onreceive function of the member variable mintentreceiver of the mediaplaybackservice class in the mediaplaybackservice. Java file.
The mediaplaybackservice. Java file is located in the packages \ apps \ music \ SRC \ com \ Android \ music directory.
The Code is as follows:
(1) Parameter definition:
public static final String CMDPAUSE = "pause";public static final String PAUSE_ACTION = "com.android.music.musicservicecommand.pause";
(2) receive Broadcast
} Else if (using pause. equals (CMD) | pause_action.equals (Action) {// If (isplaying () {mpausedbyothers = true;} pause (); mpausedbytransientlossoffocus = false ;}
3. log output is as follows:
(1) start playing music
07-09 17:32:20. 054 I/audioservice (289): audiofocus requestaudiofocus () from android.media.AudioManager@40592b48com.android.music.MediaPlaybackService $5 @ 405918f0
07-09 17:32:20. 054 D/mediaplaybackservice (7157): start playback
07-09 17:32:20. 554 D/mediaplaybackservice (7157): Sleep (500)
07-09 17:32:20. 554 D/mediaplaybackservice (7157): mediaplayer start
(2) start playing the video. Music receives the paused broadcast and pauses the playing of music.
07-09 17:32:34. 574 D/mediaplaybackservice (7157): mintentreceiver. onreceive com. Android. Music. musicservicecommand/pause
07-09 17:32:34. 574 D/mediaplaybackservice (7157): mediaplayer pause
07-09 17:32:34. 724 D/mediaplaybackservice (7157): mintentreceiver. onreceive com. Android. Music. musicservicecommand/pause
4. After the video is played, the broadcast of music is not sent.
In fact, after the video is played, you can send a broadcast where music continues to play. After music receives the broadcast, it determines whether music has paused. If it is paused, it continues to play.