Media Player callbacks only function for an Activity?

by Paper Coder » Mon, 02 Mar 2009 00:45:14 GMT


Sponsored Links
 So if I load a large sound from a resource, is there any way to tell if it's
ready to play?  I wish there was an isPrepared method for media player.  As
it stands now there seems like there's no way to know for sure.










Media Player callbacks only function for an Activity?

by Marco Nelissen » Mon, 02 Mar 2009 01:04:03 GMT


 


Of course there is: prepare() and MediaPlayer.create() are
synchronous, so when those return your MediaPlayer is ready to play.
If you're using prepareAsync(), then you should set an
onPreparedListener before calling prepareAsync, and that listener will
be called when the MediaPlayer is ready for playback.

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


Sponsored Links


Media Player callbacks only function for an Activity?

by Paper Coder » Mon, 02 Mar 2009 08:55:52 GMT


 I didn't realize it wouldn't return the media player until it was ready to
play.

Now the methods in media player make much more sense.  I was wondering why
there wasn't a way to create a new media player object with the new keyword,
then set the resource id.

Thanks!







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



Media Player callbacks only function for an Activity?

by Marco Nelissen » Mon, 02 Mar 2009 10:44:33 GMT


 


You can't set the resource id directly, but you can get a
filedescriptor for the resource. Something like:

MediaPlayer mp = new MediaPlayer();
AssetFileDescriptor afd =
getContext().getResources().openRawResource(R.raw.yourmp3resource);
mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(),
afd.getLength());
mp.prepare();
mp.start();

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



Media Player callbacks only function for an Activity?

by Paper Coder » Tue, 03 Mar 2009 12:06:26 GMT


 It's good to know this, especially if I encounter other classes that seem to
not be able to access resources easily.  Although, if I encounter that
situation again, it will set off a warning signal that there is probably an
easier way to do it (as in checking for a null reference in media player to
see if it's ready).

Thank again.







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



Other Threads

1. search_icon

Hi,
Hoe to show search icon in soft keyboard in android?

-- 
 Regards,
Vani Reddy

-- 

2. Am I allowed to shamelessly advertise on here?

Anywhom, just thought I would alert your attention to the free game I 
developed last weekend, called Fill Me In. It's a fun, {*filter*}ive little 
puzzle game (but of course I would say that). Have a try, and any feedback 
would be great :)

https://market.android.com/details?id=com.adgad.fillmein&feature=search_result

And if you're feeling super supportive, you can *like* the Facebook page 
(where you will also find other apps and random stuff) at 
 http://www.***.com/ 

Thanks :)

-- 
.

3. In-App Billing example service lifecycle

4. Problem with timed notification

5. HDMI out API

6. compilation error with froyo 2.2 with rowboat repo

7. dispatchTouchEvent which view hit?