You could create an array with the stuff you want to play (probably holding
your various R.raw.x). Then keep a reference to the current playing file
(e.g. an index to the array), and when the onCompletion() method is called
switch to the next file, play it, and update the global reference.
By looking at the API I couldn't find a handy method to change the data
source to resource id (like the one in the create(Context context, int
resId) method). So, maybe you'll have to keep creating new MediaPlayer
instances. (if you do so, remember to call release() after a file has
finished playing).
On Mon, Sep 27, 2010 at 1:08 AM, svebee sven.kapud...@gmail.com wrote:
Thank you, I solved it. But...how could I minimize this repetition
(this is with depth = 3, but what with for ex. depth = 10)?
mMediaPlayer.setOnCompletionListener(new
OnCompletionListener(){
@Override
public void onCompletion(MediaPlayer
arg0) {
sviraj(upper_left, up,
upper_right, left, right, lower_left,
down, lower_right, kombinacija_Array_String, 1);
mMediaPlayer.setOnCompletionListener(new OnCompletionListener(){
@Override
public void
onCompletion(MediaPlayer arg0)
{
sviraj(upper_left, up, upper_right, left, right, lower_left,
down, lower_right, kombinacija_Array_String, 2);
mMediaPlayer.setOnCompletionListener(new OnCompletionListener()
{
@Override
public void onCompletion(MediaPlayer arg0)
{
Context context = getApplicationContext();
CharSequence text = Please repeat.;
int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
});
}
});
}
});
On Sep 26, 7:34 pm, YuviDroid yuvidr...@gmail.com wrote:
Hi,
I've never used the MediaPlayer API, but by reading the docs I see this
method that might be interesting to you: setOnCompletionListener (
MediaPlayer.OnCompletionListener
http://developer.android.com/reference/android/media/MediaPlayer.OnCo...
listener)
probably you can simply add and implement this listener, and when the
method
gets called you know the current mp3 has finished playing, then you can
play
the next (or wait 1 sec and then play..).
Hope it helps!
Yuvi
On Sun, Sep 26, 2010 at 4:59 PM, svebee sven.kapud...@gmail.com wrote:
Hi,
I have String Array with some strings in it [UP,L,R,R...] and I have
some sounds (audio_up.mp3, audio_l.mp3 and so on). I want go through
all the strings in the array and play sounds accordingly with pause in
between (let's say 1 second).
for (int a = 0; a string_Array_String.length; a++) {
MediaPlayer mp = null;
if
(string_Array_String[a].equals(UPL)) {
mp =
MediaPlayer.create(Game.this, R.raw.audio_upl);
} else if
(string_Array_String[a].equals(UP)) {
mp =
MediaPlayer.create(Game.this, R.raw.audio_up);
}
try {
mp.prepare();
} catch (IllegalStateException
e) {
// TODO Auto-generated
catch
block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated
catch
block
e.printStackTrace();
}
mp.start();
}
This is OK but loop is faster than sound fields so I get overlaping -
not good.
I tried to put
try
{
Thread.sleep(1000);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
on the end of the loop but only first and second audio file are OK,
the rest are cut too soon.