PlayerHater
PlayerHater copied to clipboard
Crash when playback is started immediately after binding
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.
Facing same problem. Thanks for sharing. You solved my Problem. :smile:
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
This also makes it crash with an IllegalStateException.
@Override
public void onDestroy() {
super.onDestroy();
mPlayerHater.release();
}
Try to call it before super.onDestroy()
. Super callbacks for destroy reasons must be called at end of method
@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.