0

I've been working on a basic music player app.

I am trying to keep questions concise and so not put too much code or irrelevant info.

Basically, I want to add all mp3/m4a/wma to a long List of Strings. But no matter what methods I call from different libraries I cannot get it.

Here's what I've ended up with:

        string musicPath = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryMusic).AbsolutePath;
        string musicPath_sd = GetExternalFilesDir(Android.OS.Environment.DirectoryMusic).ToString();
        Log.Info("FILEPATHS TAG", "phone memory music directory path is: " + musicPath);
        Log.Info("FILEPATHS TAG", "sdcard music directory path is: " + musicPath_sd);

So the string musicPath is fine and returns:

Time    Device Name Type    PID Tag Message
FILEPATHS TAG   phone memory music directory path is: /storage/emulated/0/Music
FILEPATHS TAG   sdcard music directory path is: /storage/emulated/0/Music

As you can see the 'sdcard music directory' is returnign the exact same location, but really it should be: storage/**extSdCard**/MUSIC (I know this because I browsed to the songs on my phone in EZ File Explorer and checked the info button which displays the path.

I am using Samsung Note 3 on Android 5.0 API 21 as physical debugging device

halfer
  • 19,824
  • 17
  • 99
  • 186
Big T Larrity
  • 221
  • 2
  • 9
  • Note that you no longer have access to any of this on Android Q (by default) or R (for realz). Query the `MediaStore` for the appropriate MIME types, as not only will that work on newer Android versions, but it will be much faster. – CommonsWare Jun 17 '19 at 13:45
  • Ah ok I coincidentally just added info to question (im using Note 3 Android 5.0). Also thanks for your comment. I will look into it, altough I have to now find out what MIME types are and look into how to use MediaStore :D – Big T Larrity Jun 17 '19 at 13:46
  • EDIT , ignore the comment i deleted thanks :] – Big T Larrity Jun 17 '19 at 13:50
  • @CommonsWare: Can you clarify "you no longer have access to **any of this**"? Do you mean access to removable storage, or getExternalStoragePublicDirectory, or ...? – LarsH Jun 17 '19 at 13:52
  • Alas, I find this on mediaStore: https://learn.microsoft.com/en-us/dotnet/api/android.provider.mediastore ... but it is gobble_dee_gook to me haha I think i give in and make do with the internal phone Music folder for now :[ thanks anyway though guys – Big T Larrity Jun 17 '19 at 13:53
  • @BigTLarrity: see also https://stackoverflow.com/questions/5694933/find-location-of-removable-sd-card, but remember as CommonsWare says, things change with newer versions of Android. – LarsH Jun 17 '19 at 13:55
  • thanks Lars, I've been trying stuff much like that all night haha, but they always seem to result in the same filepath, or one that is very long and seems like 'Internal' ie myapp specific data locations – Big T Larrity Jun 17 '19 at 13:57
  • It's clearly my fault but I've kinda delved into a rabbithole with this, because honestly I am just trying to make my own music app that plays music quickly without all the bloat that the ones on PlayStore has. Maybe i end up hard coding the other path (grrrrrr hate doing that :D ) – Big T Larrity Jun 17 '19 at 13:58
  • @CommonsWare Does MediaStore contain a single list anywhere, that contains a reference to all the media on both disks? – Big T Larrity Jun 17 '19 at 14:01
  • 2
    @LarsH: "Do you mean access to removable storage, or getExternalStoragePublicDirectory, or ...?" -- pretty much all of the above. Locations that you get via methods on `Context`, such as `getExternalFilesDirs()`, are available. Other locations on external and removable storage are inaccessible. There is a way to opt out of this change for Android Q, but it will be required for all(?!?) apps in Android R, which is why developers should start adapting now. See https://commonsware.com/blog/2019/06/07/death-external-storage-end-saga.html for more. – CommonsWare Jun 17 '19 at 14:07
  • I see from here now: https://developer.android.com/reference/android/provider/MediaStore that MediaStore has a static method 'Set' 'getExternalVolumeNames' that returns a list Strings of all specific volumes that make up VOLUME_EXTERNAL. But please can anyone tell me how to call that from my code, Ive using 'Android.Provider' and I tried MediaStore.Set, MediaStore.Audio.Get... and hundreds of similar combinations without any joy. The GetExternalVolumeNames method isnt found# – Big T Larrity Jun 17 '19 at 14:11
  • Try ListFiles from following : https://developer.android.com/reference/java/io/File – jdweng Jun 17 '19 at 14:22
  • I was trying that originally haha, but i kept getting told off by the IDE for trying to instantiate a static object – Big T Larrity Jun 17 '19 at 14:25
  • really appreciating the help being offered thogh guys – Big T Larrity Jun 17 '19 at 14:26
  • so far i ended up with this: string musicPath_mediastore = MediaStore.Audio.Media.GetContentUri("extSdCard").ToString(); but it gives me a string "content://media/extSdCard/audio/albums/ which obviously isn't what i need. but hey i make progress. I have to go work in 30 mins with my annopyingly slow and bloated music player app again :[ lol – Big T Larrity Jun 17 '19 at 14:28
  • @BigTLarrity Have you got the solution? – Jessie Zhang -MSFT Jun 18 '19 at 02:21
  • @JessieZhang well kindof... I decided to hard-code the line and build the APK. I then realised writing this app in C# meant the apk size was pretty big for such small app. I decided to start trying same app in Java/Android Studio. Following https://www.sitepoint.com/a-step-by-step-guide-to-building-an-android-audio-player-app/ tutorial I found that creating an 'Audio' class and then using the MediaPlayer class I could make a list of type Audio which includes the names, genres, filepath etc in a neat package. The app i have in Java works plays all my music and is 648kb only in size – Big T Larrity Jun 18 '19 at 14:54
  • must admit though didn't understand the entire tutorial (some of it felt a bit like paint-by-numbers). But I feel confident in that the way shown in that tutorial is pretty efficient and up-to-date. And I am now in the process of trying to understand his tutorial 100% so I can move forward with that knowledge and build a better app – Big T Larrity Jun 18 '19 at 14:57
  • i THINK that i ultimately used this line (in Java) to get the entire "External Content" which i believe gets both sdcard and internal sdcard: " Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;" but there is lots of work besides that to get to that stage. That linked tut explained it all prettywell though, im just working through it again now to understand it better – Big T Larrity Jun 18 '19 at 15:11

0 Answers0