OxygenCobalt / Auxio

A simple, rational music player for android
GNU General Public License v3.0
1.8k stars 118 forks source link

Music library does not update immediately #220

Closed foss- closed 1 year ago

foss- commented 1 year ago

Describe the bug:

using Syncthing to sync music to an sd card. After removing some albums the songs keep showing in Auxio despite the files no longer residing on sd card.

Expected behavior

Removed files should no longer show in Auxio.

Steps To Reproduce the bug/crash:

Remove some files.

Active Settings:

Feels as if there is a problem either with caching or with automatic reloading. Interestingly also a manual reload does not resolve the problem. When playing one of the removed tracks (that still show) nothing plays and Auxio moved to the next track.

Phone Information:

LineageOS 19.1

Due Diligence:

illdeletethis commented 1 year ago

multiple manual reloads will do it, if it still works the same way it did a few versions ago

OxygenCobalt commented 1 year ago

Seems like your MediaStore implementation is borked and takes awhile to update while also refusing to notify ContentObserver instances of updates. Did previous versions (2.5.0) work, or has it always been like this? @foss-

foss- commented 1 year ago

Been asking that myself and sorry but can't say for sure, since I had not removed files in the past after starting to use Auxio.

What I know is that even after 4 or 5 manual refreshes the files still remain in the library. Double checked but they are gone from the sd card. I am wondering if a corruption happened as Auxio was refreshing the library while Syncthing was still copying files.

Interestingly when I open Settings > Music folders I see No folders for both Exclude and Include. So selected Include and added the music folder. That didn't change things. Also I found the UI confusing since the folder listing then showed that folder independent of whether I selected Exclude or Include. For testing I added an exclude folder, then two folders were listed but there was no way of telling which folder was excluded and which was included. But this is off topic and I should probably file another issue about that aspect.

OxygenCobalt commented 1 year ago

Huh, I want to say that this is device-specific. Can't reproduce it on my device.

(As for the music folders setting, the UI is a mess. It was primarily designed so I could simplify my internal query logic, as the interactions between included and excluded folders is really complex0

foss- commented 1 year ago

Un- and re-installed Auxio. Interestingly it still found that deleted album. I don't find any files for that album on the sd card and the music folder on phone is empty.

Wondering where from Auxio is still picking up that file info and what I can do to even find traces of that album or maybe clear some cache for the sd card? Certainly could nuke the sd card and then copy all music over but if possible would like to avoid that since that takes a while.

OxygenCobalt commented 1 year ago

Auxio gets music info from MediaStore, if it goes stale, Auxio's music will be too.

There are so many issues with that API that it's not even funny. SD Cards in particular give it the most pain.

foss- commented 1 year ago

Quick update: After a few more manual updates and after the re-install the outdated information is gone and a few albums with missing covers how show covers. So one or the other may have helped in this specific local setup problem.

e-zk commented 1 year ago

Just FYI I find a reboot can help with MediaStore not detecting albums or missing cover info. It doesn't always help, but it can sometimes.

OxygenCobalt commented 1 year ago

That would check out. I've had a similar issue in development emulator instances where MediaStore would not update, and I had to reboot in order to rescan.

hakmad commented 1 year ago

I think rebooting causes MediaStore to do a sort of hard reset - it either rebuilds the database or it just resets the cache. Either way, this issue sounds pretty similar to what happens when I add new files, so I'm pretty sure the issue lies with MediaStore (or maybe LineageOS's implementation of it - I'm also on LineageOS 19.1).

My workflow for adding new music is to download it with youtube-dl via Termux, and then shut down/turn my phone. If I restart, then it doesn't work. This workflow also solves other issues like changing tags or deleting files.

One thing I find a bit curious is that Vinyl Music Player has an option in the menu to "Scan Media". I want to say that running this option also causes a MediaStore refresh, because if I download new music and press that option, the new music will appear not only in Vinyl but also in all my other music players. Unfortunately, I don't know much about Java/Android to figure out exactly how it is doing this but I'll try to take a look at the source code and (if it's compatible with your code) you could try add it in when performing a manual reload? If it's not too much trouble of course.

Edit: I've tried to take a look at the source code of Vinyl and it doesn't look like the method it uses to refresh MediaStore would work here. I have no clue to be honest though.

Edit 2: and I've just realised that this a marked as "wontfix", my bad. :sweat_smile:

OxygenCobalt commented 1 year ago

Yeah. There is this API that allows apps to rebuild MediaStore that was accidentally made public and pretty much does not work anymore on new versions. Vinyl is one of those apps that still uses the requestLegacyExternalStorage magic flag to accomplish things like that, something I will not do since it locks your app in Android 10's compatibility mode forever.

Cwpute commented 7 months ago

Did some thorough testing this afternoon only to find this is an MediaStore problem and not an Auxio or file browser problem :( This delay in updating the folders really is painful, and even after reveral reboots some folders still won't update.

As a (slow) workaround, i'dd suggest renaming an incriminated and previously unrecognized folder, then rebooting, renaming another one, rebooting… as for some reason MediaStore only seems to take a few changes into acount after a hard reset. This will make the renamed folders and their countent appear in Auxio tagged accordingly.

In hope MediaStore is fixed and updated soon… 🤞

Cwpute commented 7 months ago

If it's of any use, my device is a Nokia TA-1157 running on Android 11.

OxygenCobalt commented 7 months ago

It's extremely unlikely MediaStore will ever be fixed, sadly @Cwpute. Google really doesn't care about improving local music access since not a lot of apps use it. You just kind of have to hope that a new phone won't have the issue. Pixels in particular seem to have the least MediaStore issues, from my observations.

Cwpute commented 7 months ago

Google's Pixel phones ? how strangely convenient for them… 🙄 Thanks for recommandation.

OxygenCobalt commented 7 months ago

I think it's more coincidental than intentional, even if it benefits them. Again, Google really could not care less about the vanishing minority of MP3 nerds. Pixels are much closer to vanilla android than other devices, and the team working on the skin they do have (probably) maintains better testing practices than other OEMs. Both of these result in less weird breakages like this.

OxygenCobalt commented 7 months ago

P.S: You might want to track #322. I don't know how it'll work, but I think when I move Auxio closer to the direct filesystem primitives this situation may improve @Cwpute.