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. Music Player lacking EQ

One thing Android's music player lacks is enhancing the audio. Other
phones (Blackberry, iPhone, etc) have ways to boost the audio level
or, most importantly, control the bass output via an Equalizer. With
no EQ, the Android music experience is rather drab.

I have heard from developers it would be hard to implement on a third
party app. However, Samsung has this feature on their music player in
the Android based Behold II. Also, Motorola added an Equalizer to the
music app in the Milestone (Droid) in Europe. So it can be done but it
sounds hard.

I hope someday the stock app or other third party apps have new
enhanced audio options. The easiest thing for Google to do would be to
stop ignoring the audio codes of Android/ API and work on that part of
the framework. Android needs enhanced media!

just wanted to share my 2 cents.

-- 

2. Android Bootcamp training class in NYC w/ Marko Gargenta

Hi All,

Marakana is taking it's Android Bootcamp training class to NYC, March
8-12, 2010. Marakana's Marko Gargenta who has been one of the top
advocates of the Android platform will be the instructor for the NYC
edition of Android Bootcamp.  Marko hosts the SF Android Meetup and
speaks regularly at conference across the globe on Android.  Not only
has Marko written all of Marakana's Android courses (from SDK to
internals) he has also trained development teams from the top mobile
carriers and service providers over four continents. Don't miss this
great opportunity to take this public class with one of the top
Android instructors in the US.


For more info on Marakana's Android Bootcamp:
http://marakana.com/training/android/android_bootcamp.html

Contact me regarding coupons and group discounts:
Rooz (at) Marakana (dot) com

Course Summary

AndroidBootcamp Training Course is a hands-on guide to designing and
building mobile applications using Google's Androidopen-source
platform. The course explains what Androidis and how it compares to
other mobile environments, the setup of the AndroidEclipse-based
development tools, the AndroidSDK, all essential features, as well
as the advanced capabilities and APIs such as background services,
accelerometers, graphics, and GPS.

This complete hands-on course encourages students to learn by building
increasingly more sophisticated and meaningful mobile applications for
Androidphones.

By the end of the course, each participant will build their own
complete Android application incorporating most of the key aspects of
the platform. Typically, we build a Twitter app for Android, but there
are other choices depending on participants' interests.

-- 

3. How can Camera API support two camera device?

4. App Compatibility between Droid and Nexus One

5. How to Generate Android Testing Report in HTML Automatically

6. Remote data access or Web Services

7. HTC's media player on the HTC Hero is misbehaving and is intercepting all the Bluetooth media buttons