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. How to attach source to classes in android.jar?

Hello,

I'm using Eclipse ADT and have created a standard Android project (using the
ADT wizard to do so). I would like to be able to browse from my source code
into the source code for any Java class inside android.jar.

I've downloaded the source code for the Android base Java APIs (git tag
"android-1.0" of repo /platform/frameworks/base). But when I attempt to
attach source to any class found in android.jar, I get the following
message:

"The JAR of this class file belongs to container 'Android Library' which
does not allow modification to source attachments on its entries."

(To see the above message, just place the cursor in your source editor on
any Android class name and hit F3.)

Any ideas on how I can set ADT up so that I can browser the source for
classes inside android.jar?

Thanks!

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

2. Maps API Key to run in emulator, is it necessary??

hi there,

kind of confused with this, found  two documentations:

http://code.google.com/android/toolbox/apis/mapkey.html
Stated:
Because MapView gives you access to Google Maps data, you need to
register with the Google Maps service and agree to the applicable
Terms of Service before your MapView will be able to obtain data from
Google Maps. This will apply whether you are developing your
application on the emulator or preparing your application for
deployment to mobile devices.

http://code.google.com/android/reference/com/google/android/maps/package-descr.html
Stated:
In order to use a MapView in your app, you need to include the
"android:apiKey" attribute in the MapView (or include a key in the
MapView constructor). For now, just put any value there (e.g.,
"myapikey")

so, do I need it or not?

Also, where can I find any sample that loads a map? App demos in the
SDK dont load any...

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

3. Does a library loaded via <uses-library> load the library into shared memory?

4. Is it possible to add a custom link in the "Share Picture Via" dialog?

5. Two new apps, one for Facebook Chat, the other for Twitter

6. How to put a dialog box to another activity's foreground?

7. Dalvik and BOOTCLASSPATH