How to provide consistent timing of audio sequencing across various Android devices and OS Versions? -
i have created metronome-type application specified swing interval of 750 milliseconds on pendulum , playing single audio file @ maximum swing arc... repeating swinging of pendulum , playing of sound indefinitely. however, finding actual timing of execution of code varies dramatically device-to-device , performs variance on single device. intent swing pendulum @ rate of 80 beats per minute , play audio file each "beat". adjusted 750 millisecond setting accommodate time required play audio file. reduced millisecond setting 750 down 680. tested using various devices , found results of 1 minute run of metronome performed dramatically differently timing tested various android devices though defining timing elements based on milliseconds.
i using android soundpool access .wav file play sound.
i found quite few references soundpool timing issues , concerns have not yet found viable , reliable solution deliver consistent timing application this.
it seems swing of pendulum pretty consistent based on specified delay believe variation due variable timing during execution of soundpool code playing audio. there reliable way execute code play sounds on consistent , "exact" timing interval android?
one way handler. allows start audio clip @ same time regardless of how long clip takes play. don't need soundpool this, soundplayer.
a handler allows schedule message delivered code time in future. since playing sound soundplayer asynchronous, can use simple mechanism play sound on regular interval.
here code show how might work.
handler = new handler() { /* (non-javadoc) * @see android.os.handler#handlemessage(android.os.message) */ @override public void handlemessage(message msg) { if (msg.what == next_sound_msg) { playnextsound() } } }; // set media player sounds player = new soundplayer(context); player.start(); private void playnextsound() { if (mrunning) { // play sound int isoundresid = item.getsoundresid(); if (isoundresid != -1) { playsound(isoundresid); } // schedule message advance next item after duration message msg = handler.obtainmessage(next_sound_msg); handler.sendmessagedelayed(msg, interval); } }
Comments
Post a Comment