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. Listening to Home key Intent

Hi All,

I found out from the forum that overrding the HOME key is not possible
in android. I need to have my application to have complete control
over the device.
So I tried to write a broadcast receiver to listen to the HOME intent
but was not successful. Still on presssing the HOME button the Home
screen would launch.

The manifest is like:

         <receiver android:name="StartupIntentReceiver">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.HOME" /
            </intent-filter>
        </receiver>

Could some one please help with the feasibility of this?

-- 

2. location for insmod scripts

Hi,

I have to insmod the kernel modules for netfilter to init iptables at
boot up.
I have written a small shell script that insmods the modules in a
specific order.
How and where I can schedule an automatic execution of this file?

I have tried modifying init.goldfish.sh, but the script does execute.

Cheers,
Earlence

-- 

3. beli desire hd di spore

4. Tampilan market baru

5. MotionEvent not firing as expected

6. Beda GApps, apa itu?

7. Have to create a ExpandableList with different types of childs