doublesymmetry / KotlinAudio

KotlinAudio is an Android audio player written in Kotlin, making it simpler to work with audio playback from streams and files.
Apache License 2.0
45 stars 70 forks source link

Fix NullPointerException #75

Closed ricardocmj closed 1 year ago

ricardocmj commented 1 year ago

Fixes https://github.com/doublesymmetry/react-native-track-player/issues/1997

This error happens due to a race condition with hideNotification():

https://github.com/doublesymmetry/KotlinAudio/blob/558fb7f963590813f7e629c73e3c4f9cb29f74f7/kotlin-audio/src/main/java/com/doublesymmetry/kotlinaudio/notification/NotificationManager.kt#L518-L520

or with destroy():

https://github.com/doublesymmetry/KotlinAudio/blob/558fb7f963590813f7e629c73e3c4f9cb29f74f7/kotlin-audio/src/main/java/com/doublesymmetry/kotlinaudio/notification/NotificationManager.kt#L544-L546

bradfloodx commented 1 year ago

Hi @jspizziri, are you able to review this? I'm facing this error using V4 RC03.

Thank you! 🙏

jspizziri commented 1 year ago

@bradleyflood just took a look. Not sure how there could be a problem caused by this line.

bradfloodx commented 1 year ago

Thanks :)

I'm still debugging this now. But for me it happens during normal playback. I'll have an audio file playing fine, and then I click Play on that same audio file again and sometimes I get:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.tutusgumboots.evergrace, PID: 11325
    java.lang.NullPointerException: null cannot be cast to non-null type com.doublesymmetry.kotlinaudio.models.AudioItemHolder
        at com.doublesymmetry.kotlinaudio.notification.NotificationManager.getCurrentItemHolder(NotificationManager.kt:159)
        at com.doublesymmetry.kotlinaudio.notification.NotificationManager.setNotificationMetadata(NotificationManager.kt:54)
        at com.doublesymmetry.kotlinaudio.players.BaseAudioPlayer.updateNotificationMetadataIfAutomatic$kotlin_audio_release(BaseAudioPlayer.kt:286)
        at com.doublesymmetry.kotlinaudio.players.BaseAudioPlayer$PlayerListener.onMediaItemTransition(BaseAudioPlayer.kt:646)
dcvz commented 1 year ago

Thanks for the investigation! Will go out with the next RC and nightly