Reference MediaPlayer object from multiple activities

All your problems with Audio, Video and Images.

Reference MediaPlayer object from multiple activities

Postby fredley » Sat Apr 17, 2010 5:10 pm

I've got an app that streams music from a site and plays it. This works, but currently each track you select is making a new MediaPlayer object, instead of stopping the previous one and starting the new track. I need to have a global MediaPlayer object that each Track activity can use, however I can't put a reference to the MP object into the bundles I send to each Track Activity (which opens a new window to display track info). How can I get around this?
fredley
Freshman
Freshman
 
Posts: 6
Joined: Fri Apr 16, 2010 8:04 pm

Top

Re:Reference MediaPlayer object from multiple activities

Postby adnorid » Mon Apr 19, 2010 6:44 am

you can have a service running in the background that has the MediaPlayer instance. Then you can connect to this service from several Activities...
adnorid
Junior Developer
Junior Developer
 
Posts: 10
Joined: Fri Apr 16, 2010 10:03 am

Postby fredley » Mon Apr 19, 2010 10:41 am

That sounds like quite a good idea actually. Currently I've created my own MediaPlayer extended class, and created a reference to it in my singleton class, which extends the Application class, and is accessible from anywhere via:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. state = (StateApp) context.getApplicationContext();
  3.  
  4. MyMediaPlayer mp = state.getMediaPlayer();
  5.  
  6.  
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


This works well in terms of providing universal access to the same MediaPlayer, but it often hangs and crashes the app (I think this is due to the app streaming large (50MB+) mp3s, it often just gets stuck buffering.
fredley
Freshman
Freshman
 
Posts: 6
Joined: Fri Apr 16, 2010 8:04 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 14 guests