souch / SMP

SicMu Player for android
GNU General Public License v3.0
29 stars 8 forks source link

Doesn't find music in Syncthing's folder #24

Closed jpellegrini closed 6 years ago

jpellegrini commented 6 years ago

Hello,

I have a Xiaomi Redmi Note 4 running crDroid (which is based on LineageOS, Android 7.1.2) I would like to sync my music with another device using Syncthing. But Syncthing can only synchronize files inside its own folder (externalSD/Android/data/com.nutomic.syncthingandroid/files/...) so I created a "music" folder there:

/storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/

But Sicmu won't find it, I don't know why.

I got the sources from Github, and uncommented the line that logs the filenames being scanned (in Settings.java), compiled, installed and checked the logs:

    private void scanMediaFiles(Collection<File> filesToScan) {
        String[] filesToScanArray = new String[filesToScan.size()];
        int i = 0;
        for (File file : filesToScan) {
            filesToScanArray[i] = file.getAbsolutePath();
            //if (filesToScanArray[i].contains("emulated/0"))
                Log.d("Settings", "fileToScan: " + filesToScanArray[i]);
            i++;
        }

        if (filesToScanArray.length != 0) {
            MediaScannerConnection.scanFile(this, filesToScanArray, null, null);
        } else {
            Log.e("Settings", "Media scan requested when nothing to scan");
        }
    }

So -- when I click on "Rescan Media Files", Sicmu does find the files in syncthing's folder:

01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-10-Andros_Ballos.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-07-Black_Sea_7.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-15-Versipellis_Solo_Dance_Piece.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-04-Beranche.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-14-New_Town_Klezmer.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-01-Irish_Fairy_Remember_the_Oscar_Wilde.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-03-Americana_Jam.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-08-Hobbiton_Triplets_of_Hobbitville.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-11-Egyptian_Ella.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-13-Government_Housing.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-12-Luminate_Gaels_Revenge.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-09-Shanghai_Pancakes.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-05-Patrices_Klezmer.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-02-It_Aint_Right.mp3
01-01 11:48:37.413  8365  8365 D Settings: fileToScan: /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files/music/tuo-tales-from-the-road/The_Underscore_Orkestra-06-Sail_Boat.mp3

However, no files from Syncthing's folder in the exteral SD card show up in Sicmu. I have waited several minutes after rescanning the media, but it did not work. I also tried killing Sicmu and even rebooting.

If I create a folder /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/XYZ/

and include an mp3 file there, Sicmu will find and include it. But inside /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/ it seems to scan the files, but not include them.

What could be going on?

Thanks, J.

souch commented 6 years ago

I looked a bit to your problem but did not find a solution still. I'll see it again when I'll have time.

jpellegrini commented 6 years ago

So --

Pretty Good Music Player does find music in Syncthing folder. It looks like the code that does it is here:

src/com/smithdtyler/prettygoodmusicplayer/SongList.java

However, it has a somewhat different way to sort music -- see issue 111

J.

souch commented 6 years ago

I looked at prettygoodmusicplayer. To list files, it does not use the ContentResolver of Android (Android built-in dictionnary of media files). It seems to just recursively list files from a chosen dir.

private static void _getAllSongsInDirRecursive(File target, List<File> songFiles)
...

next() {
...
            songFile = new File(next);
            fis = new FileInputStream(songFile);
            mp.setDataSource(fis.getFD());
            mReadaheadThread.setSource(songFile.getAbsolutePath());
            mp.prepare();
            mp.start();

So it is a really different way of fetching files from the device. If there are a lot of files, isn't prettygoodmusicplayer slow when it starts ?

I think, the problem you've got with SMP is the Android's ContentResolver don't want to index files that should be private to the syncthings app. And I rather would agree with that.

Can't you configure syncthings to put files on another dir, near the root of your public internal storage, rather than in /storage/bb14cf63-4fcb-2231-acd6-c13f992d15e3/Android/data/com.nutomic.syncthingandroid/files ?

jpellegrini commented 6 years ago

Yes -- prettygoodmusicplayer does recursively list files...

It seems that this is a problem with Android's permission model. SMP could in theory go there and read the files, but Android own method (ContentResolver) will not do it. Anyway -- Syncthing is supposed to be used to sync folders, so it would make sense for me to read what's in its folders... But Syncthing doesn't seem to be able to sync any folder in the SD card, but only those in its subfolder.

I'm not sure what to do. Pretty Good Music Player isn't slow when I open it -- it's just fine. But I like SMP's interface and features much more.

Now -- I understand why you wouldn't want SMP to just go opening whatever folder the user gives it. On the other hand, if it did, then you could sync your music folder with other devices using Syncthing (which is great!)

It's up to you, of course!

-- J

souch commented 6 years ago

I just installed syncthings, and it seems it is possible to put shared file in another dir than the one you chosen.

I installed also prettygoodmusicplayer, and yes, the start is not slow cause it lists only the files and dirs at the level it is. Honestly, I don't think this player is neither pretty nor good :-).

jpellegrini commented 6 years ago

I just installed syncthing, and it seems it is possible to put shared file in another dir than the one you chosen.

Actually, it won't work; it accepts the folder path but won't sync (at least not if the folder is in the external SD card).

souch commented 6 years ago

ok, but that's a syncthings bug.

jpellegrini commented 6 years ago

Not really a syncthing bug:

https://github.com/syncthing/syncthing-android/issues/225 https://github.com/syncthing/syncthing-android/issues/29

"things were changed in 4.4, and we currently don't have a way to write to external storage."

In my opinion, it's an Android bug. :-( An app like syncthing cannot write outside its own folder in the external SD card.

OK -- there isn't much to do I suppose.

souch commented 6 years ago

Syncthink cannot write on the external SD but can write wherever it wants on the internal SD. So you can put your synced files in a folder like this : /storage/emulated/0/sync, and SMP will see them.

jpellegrini commented 6 years ago

Yes, I know it can write to the internal sd card -- which isn't enough for the music I have; that's why I wanted to sync the external card, and not the internal one.

But I'll see what other solution I can find.

souch commented 6 years ago

Ah, ok.