Greetings fellow androidians, I need to provide the facility to play multiple sounds (which could be large) concurrently and to know once each sound has finished playing.
Unfortunately this results in my sounds being played back quite randomly. Sometimes the first sound is truncated before the second starts, sometimes they play over the top of eachother correctly, and sometimes they start together but one (or both) cuts out prematurely! I can't use the soundpool as I want to detect when each sound has finished playing. My code: private void playSound(final File f, final Runnable onFinish) { runOnUiThread(new Runnable() { public void run() { try { FileDescriptor fd = new FileInputStream(f).getFD(); MediaPlayer mp = new MediaPlayer(); mp.setDataSource(fd); mp.setAudioStreamType(AudioManager.STREAM_MUSIC); mp.prepare(); mp.start(); mp.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer mp) { mp.release(); if (onFinish != null) onFinish.run(); } }); } catch (IOException io) { logError(io); } } }); } The log does indicate some kind of event is being removed from the queue and a write being blocked: W/AudioFlinger(15290): write blocked for 159 msecs, 146 delayed writes, thread 0xd7e0 W/TimedEventQueue(15290): Event 8 was not found in the queue, already cancelled? D/dalvikvm(25327): GC_FOR_MALLOC freed 5468 objects / 497648 bytes in 41ms W/TimedEventQueue(15290): Event 20 was not found in the queue, already cancelled? D/dalvikvm(25327): GC_EXTERNAL_ALLOC freed 424 objects / 26632 bytes in 30ms I/AudioHardwareQSD(15290): AudioHardware pcm playback is going to standby. Does anyone have any ideas on what is going on? Are you only allowed to prepare one mediaplayer at a time??? Regards, Peter Carpenter. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en