简体   繁体   中英

Steady sound playing in Android with Mediaplayer

I'm developing my application but i came across a problem.

When starting my app it retrieves information from database . Then It draws notes on the screen according to the information from database , it draws hi hat, snare and kick notes , if it has to be played the note is black when not it is gray.

The next step is that im using rx java to call a method called highLightNotes() .

Observable.interval(400, TimeUnit.MILLISECONDS).subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Long>() { @Override
        public void onNext(@NonNull Long aLong) {
            highLightNotes(aLong);
        }

the next step is that it is looking for black notes, and when the note is black it calls this method :

public void playSnare(){
    snarePlayer.seekTo(0);
    snarePlayer.start();
}

snarePlayer is a mediaplayer.

My first problem here is that it takes way too much time to hear the note. The rhytm is becoming unsteady as sometimes it takes more time to get through sometimes less.

The second problem is that im kind of rxjava noob obviously and i'm wondering why by clicking for the first time to play the rhytm it takes a couple of seconds to get it started and then it is played really fast and after that i becomes steady .

Please provide me with some more information to keep working on it , im stuck.

You're starting up a new thread the first time. See where you're telling it to subscribe on a new thread?

If you need tight control over timing like this, RxJava is NOT the way to go. You do not want a giant codebase swapping you between threads. You're just asking for pain.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM