hello,
i want to play a very short click sample, when counting up the score, so lets say player has scored 50000 points, i want to count up from 0 to 50000 in maybe 3 seconds and on every count, i want to play a short sample
the sample comes from a resource id, so i initialize it with
when i now use p.start(), it plays one but never again.Code:MediaPlayer p=MediaPlayer.create(mContext, R.raw.sample);
api docs say i should use reset() and setDataSource(), but there is no setDataSource for resource id's.
now i tried something like
but it slows everything downCode:class MyClass { MediaPlayer p=null; void playSound() { if (p!=null) p.reset(); p=MediaPlayer.create(mContext, R.raw.sample); p.start(); } }
so how can i achieve this?
I blame
To view links or images in signatures your post count must be 5 or greater. You currently have 0 posts.
for most programming problems.
thanx for answer
after calling reset() you need to call setDataSource() again, which does not support a resource id (which i think is a problem of the api, if there is a create() with resource id, there should be a setDataSource(Context context, int resid) )
setLooping works for the special case of counting up the scores, but i also want to play a sound on single actions, so it is no option for that.
seekAt(0) would be exactly what i need, but no matter what i do, after using seekAt(0), the sound does not play anymore.
Looks like you'll have to .release() your previous MediaPlayer before instantiating a new one until Google fixes the API.
You may also want to try Context's getResources().getResourceName(int resId). If getResourceName() gives you the proper name back, you could try using that value in MediaPlayer's setDataSource().
I blame
To view links or images in signatures your post count must be 5 or greater. You currently have 0 posts.
for most programming problems.
here is the best solution i came up with:
whereas PACKAGE_NAME is what ever is specified in AndroidManifest.xmlCode:class MyClass ... { AsyncPlayer aPlayer=new AsyncPlayer("aPlayer"); public void doStuff() { aPlayer.play(mContext, Uri.parse("android.resource://"+PACKAGE_NAME+"/"+R.raw.soundfile), false, AudioManager.STREAM_SYSTEM); } }
I'd file the lack of a resId in .play() as a bug on http://b.android.com.
I blame
To view links or images in signatures your post count must be 5 or greater. You currently have 0 posts.
for most programming problems.
Bookmarks