fast4x / RiMusic

A multilingual Android application for streaming music from YouTube Music.
https://rimusic.xyz
GNU General Public License v3.0
2.56k stars 131 forks source link

App Crashes when persistent queue is enabled #4492

Closed Abhinavreddy-B closed 1 week ago

Abhinavreddy-B commented 1 week ago

Version of RiMusic

0.6.59 (both normal build and custom build)

Android version

11

I've done these:

Tell us how you trigger this bug

  1. Enable persistent queue in the app
  2. start playing a song, pause it, and close the app
  3. again open the app, wait for a few seconds the app crashes.

Note: It crashes only when persistent queue is enabled.

Also Note, crash is taking a couple of seconds to happen, upon quickly interacting with the player (before these couple of seconds) doesn't make the app crash.

I tried to extract full app logs using the custom build, I am attaching the catlog file below (I hope it would help)

log.zip

Submit a video

If you are on Android, please download a screen recorder and record your screen while you duplicating the problem as describe above.

You may need to use Github App to be able to upload video - size limit is 10 MB.

If you are on Desktop, drag video into this box and it will be uploaded automatically

https://github.com/user-attachments/assets/8a9d4ab1-d47e-459f-aadb-d7473ef71b12

What was your expectation?

shouldnt crash

What more can you tell us? (Optional)

No response

Logs (Optional)

log.zip

Abhinavreddy-B commented 1 week ago

I already attatched (above) the full app logs extracted from logcat using custom build, those would be much helpful than apps crash logs, but never the less these are the crash logs of the app:

2024-11-12T16:47:52.993:    android.app.ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{f443eb6 u0 it.fast4x.rimusic/.service.modern.PlayerServiceModern}
     android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2078) 
     android.app.ActivityThread.access$2800(ActivityThread.java:259) 
     android.app.ActivityThread$H.handleMessage(ActivityThread.java:2303) 
     android.os.Handler.dispatchMessage(Handler.java:106) 
     android.os.Looper.loopOnce(Looper.java:233) 
     android.os.Looper.loop(Looper.java:344) 
     android.app.ActivityThread.main(ActivityThread.java:8249) 
     java.lang.reflect.Method.invoke(Native Method) 
     com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:589) 
     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1071) 

2024-11-12T16:49:16.627:    android.app.ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{aa58bcb u0 it.fast4x.rimusic/.service.modern.PlayerServiceModern}
     android.app.ActivityThread.throwRemoteServiceException(ActivityThread.java:2078) 
     android.app.ActivityThread.access$2800(ActivityThread.java:259) 
     android.app.ActivityThread$H.handleMessage(ActivityThread.java:2303) 
     android.os.Handler.dispatchMessage(Handler.java:106) 
     android.os.Looper.loopOnce(Looper.java:233) 
     android.os.Looper.loop(Looper.java:344) 
     android.app.ActivityThread.main(ActivityThread.java:8249) 
     java.lang.reflect.Method.invoke(Native Method) 
     com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:589) 
     com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1071)
Abhinavreddy-B commented 1 week ago

I dont know much about kotin, nor android applications.

but this piece of code looks suspecious to me:

In PlayerService.kt, Inside the function maybeRestorePlayerQueue:

runBlocking(Dispatchers.Main) {
                player.setMediaItems(
                    queuedSong.map { mediaItem ->
                        mediaItem.mediaItem.buildUpon()
                            .setUri(mediaItem.mediaItem.mediaId)
                            .setCustomCacheKey(mediaItem.mediaItem.mediaId)
                            .build().apply {
                                mediaMetadata.extras?.putBoolean("isFromPersistentQueue", true)
                            }
                    }
                    // ... blah blah...
   }

https://github.com/fast4x/RiMusic/blob/49afd310c9ec6caa1285faa09445d90c6c1d9120/composeApp/src/androidMain/kotlin/it/fast4x/rimusic/service/PlayerService.kt#L1126C1-L1129C1

So this is blocking the main thread, and as seen in the logs, the OS thinks the application Hung, and force closes the application or something.

what do you guys think??

Abhinavreddy-B commented 1 week ago

Sry, its not PlayerService, its PlayerServiceModern.

https://github.com/fast4x/RiMusic/blob/49afd310c9ec6caa1285faa09445d90c6c1d9120/composeApp/src/androidMain/kotlin/it/fast4x/rimusic/service/modern/PlayerServiceModern.kt#L1338C1-L1346C1

fast4x commented 1 week ago

Fixed and available next version, thanks