Repeating a sound

Search This thread

jordanstreet

New member
Dec 28, 2010
2
0
Hey guys I'm building a metronome and am using the MediaPlayer.
Code:
MediaPlayer mp;

.....

public void run() {
    		if(playing) {
    			mp.seekTo(0);
    			mp.start();
    		}
    		else
    		{
    			mp = MediaPlayer.create(getBaseContext(), R.raw.cowbell);
    	 		mp.start();
                        playing = true;
    		}
}

the run method is called in regular intervals. There is a delay between the first and second click then it seems to run smoothly. Even so at higher tempos I feel like it is phasing in and out of time. Also the fastest the sound will play is about every 300ms anything faster and there is no noticeable difference.

Any thoughts?

Thanks,
Jordan
 

jordanstreet

New member
Dec 28, 2010
2
0
I've managed to smooth things out by using SoundPool instead of mediaplayer as its more suited to this sort of thing and I can assume uses less resources. My metronome is still inconsistent though. Is there a better timing method other than using handler/runnable/postdelayed?
 
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone