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)
 http://commonsware.com  |  http://twitter.com/commonsguy 

Android App Developer Books:  http://commonsware.com/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.

-Marc






--



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)
 http://commonsware.com  |  http://twitter.com/commonsguy 

_Beginning Android_ from Apress Now Available!

--



Other Threads

1. How to automatically set system time and date using ntp or an other time service

Hi,
      Is it possible to set the time and date automatically using ntp
or an other time service, for android 1.5?

Elvis Dowson
--~--~---------~--~----~------------~-------~--~----~

2. How to overlay an icon image on top of an existing view

Hi,

If I have a reference to a view, how can I overlay an icon image on top of
an exisiting view? In the screenshot below:
http://android.kanokgems.com/sms-unread-count

It overlay an icon at the top right corner of the dialer icon. How can I do
that?

Thank you.

--~--~---------~--~----~------------~-------~--~----~

3. Choosing the Right Phone

4. auto mount the usb mass storage?

5. Jad Parameter Equilent in Android

6. Phone number format when writing to Contact database in android

7. Custom market for enterprises