Android Media Player Stuttering with CountDownTimer

[postlink] https://the-best-way-of-life-is-islam.blogspot.com/2015/07/android-media-player-stuttering-with.html [/postlink]

I'm trying to make an app to teach someone how to count music. The media player is initialize to a 30 second sound clip of a persistent A note. I am using a countdown timer to tell my media player when to pause and play. The code below causes the first and last second of audio to stutter.

MediaPlayer myMediaPlayer = MediaPlayer.create(MusicCounting.this, R.raw.a_note);
CountDownTimer time = new CountDownTimer(4000,500) {
    @Override
    public void onTick(long millisUntilFinished) {
        if(myMediaPlayer.isPlaying()) {
            myMediaPlayer.pause();
        } else {
            myMediaPlayer.start();
        }
    }

    @Override
    public void onFinish() {
        myMediaPlayer.pause();
        myMediaPlayer.seekTo(0);
    }
};

time.start();

This code is for quarter notes and my eighth notes code looks identical except the second parameter for the countdown timer is 250. Any suggestions would be greatly appreciated. Thanks :)

اذا أعجبك الموضوع ساهم في نشره :

Enregistrer un commentaire

 
حقوق النشر: Published by | Template Created by | القناة على اليوتيب
copyright © 2014. The Best Way Of Life Is Islam -يمكن نقل كل ما هو موجود في موقع الرحمة تيوب
القرآن الكريم و الأحاديث النبوية أناشيد و دروس اسلامية منوعة موقع الفيديوهات الاسلامية
تطوير و تعريب مدونة ثعلوب