Piasy / RxAndroidAudio

Maybe the most robust Android Audio encapsulation library, with partial Rx support.
http://blog.piasy.com/2016/02/24/Robust-Android-Audio-encapsulation/
MIT License
1.57k stars 235 forks source link

monitor play status #14

Closed milayihe closed 8 years ago

milayihe commented 8 years ago

How to get the play finish status?

Piasy commented 8 years ago

If you read the README carefully, you can see:

mRxAudioPlayer.play(PlayConfig.file(audioFile).looping(true).build())
        .subscribeOn(Schedulers.io())
        .subscribe(new Action1<Boolean>() {
            @Override
            public void call(Boolean aBoolean) {
                // play finished
                // NOTE: if looping, the Single will never finish, you need stop playing
                // onDestroy, otherwise, memory leak will happen!
            }
        });
milayihe commented 8 years ago

@Piasy but I found .subscribe() just monitor the start, And .doOnCompleted() monitor the finish status.That's right????

Piasy commented 8 years ago

How do you find it out? When the play is finished, the returned Single will get a onSuccess event.

milayihe commented 8 years ago

I tracked your code, found .doOnCompleted() method useful for me .

Piasy commented 8 years ago

The RxAudioPlayer.play will return a Single object, it will emit an onSuccess event when the playing is finished.

How do you use the returned Single object is totally free to you :)

milayihe commented 8 years ago

Tks a lot