PlayerHater icon indicating copy to clipboard operation
PlayerHater copied to clipboard

Crash when playback is started immediately after binding

Open flavioarfaria opened this issue 10 years ago • 5 comments

This piece of code makes the app crash:

@Override
public void onResume() {
    super.onResume();
    mPlayerHater = PlayerHater.bind(getActivity());
    mPlayerHater.play(new MySong());
}

On the other hand, this piece of code works:

new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            startPlaybackIfNeeded();
        }
    }, 1000);

It seems like the player takes some time to start. No stacktrace is provided when the crash happens.

flavioarfaria avatar Aug 09 '14 15:08 flavioarfaria

Facing same problem. Thanks for sharing. You solved my Problem. :smile:

djahmednawaz avatar Nov 14 '14 11:11 djahmednawaz

I'll take a look at this when I get a chance. I think it may require one tick but I thought I covered this

cqr avatar Sep 30 '15 12:09 cqr

This also makes it crash with an IllegalStateException.

    @Override
    public void onDestroy() {
        super.onDestroy();
        mPlayerHater.release();
    }

danvass avatar Oct 07 '15 00:10 danvass

Try to call it before super.onDestroy(). Super callbacks for destroy reasons must be called at end of method

rafaeltoledo avatar Oct 07 '15 04:10 rafaeltoledo

@rafaeltoledo That's how I originally did it but it didn't make a difference. I ended up adding the runnable snippet posted above and it seems to work or rather it doesn't crash. I'm not actually sure whether it does release because if there is only one song queued up then the audio player won't disappear and it can't close.

danvass avatar Oct 07 '15 04:10 danvass