SimpleMobileTools / Simple-Music-Player

A clean music player with a customizable widget, stylish interface and no ads.
https://www.simplemobiletools.com
GNU General Public License v3.0
1.26k stars 410 forks source link

Improve media scanner and thumbnail loading #545

Closed naveensingh closed 11 months ago

naveensingh commented 1 year ago

This PR addresses issues like https://github.com/SimpleMobileTools/Simple-Music-Player/issues/404 and https://github.com/SimpleMobileTools/Simple-Music-Player/issues/394 where users report missing music files in the player.

This PR also closes https://github.com/SimpleMobileTools/Simple-Music-Player/issues/504

Changes and notes:

I have tested these changes on API levels 23, 25, 27, 29, 30, 32, and 33 and so far everything has been working smoothly, and from what I can tell manual scan is working as well as MediaStore. Not many players can do this.

Things left to do

tibbi commented 12 months ago

if I use the scan media button in the app settings, then go back in the main activity and progress finishes, I get a crash on Android 11 12:33:05.176 E FATAL EXCEPTION: Thread-50 Process: com.simplemobiletools.musicplayer.debug, PID: 11064 java.lang.RuntimeException: setDataSource failed: status = 0x80000000 at android.media.MediaMetadataRetriever.setDataSource(Native Method) at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:244) at com.simplemobiletools.musicplayer.helpers.SimpleMediaScanner.scanFilesManually(SimpleMediaScanner.kt:116) at com.simplemobiletools.musicplayer.helpers.SimpleMediaScanner.access$scanFilesManually(SimpleMediaScanner.kt:20) at com.simplemobiletools.musicplayer.helpers.SimpleMediaScanner$scan$1.invoke(SimpleMediaScanner.kt:41) at com.simplemobiletools.musicplayer.helpers.SimpleMediaScanner$scan$1.invoke(SimpleMediaScanner.kt:39) at com.simplemobiletools.commons.helpers.ConstantsKt.ensureBackgroundThread$lambda-0(Constants.kt:429) at com.simplemobiletools.commons.helpers.ConstantsKt.$r8$lambda$ukHVGNDmwl8QsD9hCK7IQG-Hwww(Unknown Source:0) at com.simplemobiletools.commons.helpers.ConstantsKt$$ExternalSyntheticLambda0.run(Unknown Source:2) at java.lang.Thread.run(Thread.java:923)

tibbi commented 12 months ago

added a new string rescan_media to be translated while this PR gets sorted out, use it please

naveensingh commented 12 months ago

please check my reply

naveensingh commented 12 months ago

I'm checking the crash now

naveensingh commented 12 months ago

java.lang.RuntimeException: setDataSource failed: status = 0x80000000

is this crash a one-time thing or is it happening on every rescan or every time you enable/disable manual scan?

I forgot to add a try/catch block, I'm adding it now...

naveensingh commented 12 months ago

I could not reproduce that specific crash. The error code 0x80000000 equals -2147483648 meaning UNKNOWN_ERROR as can be seen in Errors.h here.

https://github.com/SimpleMobileTools/Simple-Music-Player/pull/545/commits/265d87a82be680b4ac397767f1e7550d5a42d9d5 has a workaround and catches all such crashes.

naveensingh commented 12 months ago

Check again please.

tibbi commented 12 months ago

yeah, the crash is fixed now, but I see that progress at the top at every app launch, Im not a fan of that. It takes like 20 seconds for me to finish the scanning

tibbi commented 12 months ago

plus the progress bars color isnt updated on resume, only start

naveensingh commented 12 months ago

I was only keeping it there until I add the scanning notification, removing it now...

naveensingh commented 12 months ago

Okay, now the progress bar will show up only on the first load, and when manually rescanning using Rescan media. Is that okay?

tibbi commented 12 months ago

cant we show something as soon as possible at first install, maybe the mediastore files? It takes a really long time to show anything now.

naveensingh commented 12 months ago

now that it's removed, I agree that the Scan files manually was really unnecessary. Let's hope it won't create any new device or system specific issues.

naveensingh commented 12 months ago

cant we show something as soon as possible at first install, maybe the mediastore files? It takes a really long time to show anything now.

I was gonna fix that while optimizing the scan time but if you want to release these changes soon, I can make it so that MediaStore is loaded first

naveensingh commented 12 months ago

It takes a really long time to show anything now.

How many files do you have?

tibbi commented 12 months ago

only 168 audio files are present in All tracks tab and All Tracks playlist. But my device is quite packed with photos and other files

tibbi commented 12 months ago

Im not in a hurry to release this version, just do it properly

naveensingh commented 12 months ago

okay then, I'll push all the changes here if this isn't already merged by the time I'm done.

naveensingh commented 11 months ago

Do you think Loading files... is okay or should I add Scanning... or Scanning files... strings?

Currently using the headset icon for the notification small icon.

naveensingh commented 11 months ago

I have some readability-related changes but I'll create another PR for it. There are already too many changes here.

tibbi commented 11 months ago

if the original string contains "Rescan media", we should definitely show Scanning. Loading doesnt make sense and it is not consistent.

naveensingh commented 11 months ago

okay, added "Scanning..." string in another PR just in case this one isn't merged soon: https://github.com/SimpleMobileTools/Simple-Music-Player/pull/554

tibbi commented 11 months ago

move the string into Commons while it is easy, such strings might easily be used in other apps too

naveensingh commented 11 months ago

Oka, here it is: https://github.com/SimpleMobileTools/Simple-Commons/pull/1747

Do we also want to move rescan_media to commons? Not sure which apps can reuse that.

tibbi commented 11 months ago

no, that string isnt that generic

naveensingh commented 11 months ago

ok :)

tibbi commented 11 months ago

havent found any issues at initial testing, hope it will work well. Thanks. That was a pretty big rewrite with hopefully a lot of improvements ;)