stop mediaplayer from previous activity

by MarcC » Wed, 17 Feb 2010 02:21:55 GMT

Sponsored Links
 Can anyone tell me how to stop media player that was started in a
previous activity?

For ex. In activity-1 button pressed that did - mp.start(); then
activity-2 starts for different layout with new buttons, then when
button pressed, mp.stop is called, but does not stop the media from
the first activity.

Thanks in advance.


stop mediaplayer from previous activity

by Mark Murphy » Wed, 17 Feb 2010 02:28:05 GMT


You can't directly, AFAIK.

You would need the second activity to somehow notify the first activity
to stop the playback. Ideally, you would just do all of this in one
activity, or have the MediaPlayer be managed by a service, as
activity<->activity communications on-the-fly strikes me as a more
fragile pattern.

Mark Murphy (a Commons Guy)  | 

Android App Developer Books: 


Sponsored Links

stop mediaplayer from previous activity

by MarcC » Wed, 17 Feb 2010 02:39:01 GMT

 Thank you Mark....

Do you happen to know where I can find an example of MediaPlayer as a
Service? Did some searching but what I found didn't get me to where I
wanted to be. The examples I found had a single audio being played and
stopped via the service and I could not figure out how to add more
than one audio file.



stop mediaplayer from previous activity

by Mark Murphy » Wed, 17 Feb 2010 02:41:33 GMT


I suspect the built in Music app works that way. In general, though,
MediaPlayer isn't activity-specific, so it should work in a service just
as it would in an activity. You might want to use the new
startForeground() method, though, to keep it playing and put a
Notification in the status bar at the same time.

Register a listener with the MediaPlayer and kick off the next file. If
the gap becomes a problem, consider using two MediaPlayers, working
back-to-back -- when #1 stops, you start #2 while doing prepareAsuync()
on #1 to ready it for the next go-around.

Mark Murphy (a Commons Guy)  | 

_Beginning Android_ from Apress Now Available!


Other Threads

1. Failed to install Repo

I cannot install Repo. I tried the command
curl >~/bin/repo, but the
downloaded repo is a HTML file.

cat ./bin/repo
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL /repo was not found on this server.</p>

The URL cannot be found. Is this
URL have been changed? How do I install the Repo?



2. SMS Counter


I suggestion for Android I would like to do is a build-in SMS Counter.
When having plans that allow you to do a specified amount of SMS
messages in a month, an SMS Counter would be very useful, and I can't
imagine writing code for it could be that hard.

Please consider my idea, I think that, apart from me, many people
would love this simple extra to the Android OS.



3. Adding an SD Card to an existing AVD

4. Books or WebSites about Android

5. What, if any, Intent fired for long press on home key?

6. Can Android suport 24bit color deepth display?

7. What your the policy to accept patches?