1

I'm trying to save a mp3 file, into the device's music library folder.(I Want it to show up immediately as a playable song).
More clearly i'm looking for the path /storage/emulated/0/Music/, in each phone.Im not sure if this path changes, so i would rather not take the risk.

I have tried this paths:

  • System.Environment.SpecialFolder.CommonMusic -> Blank
  • System.Environment.SpecialFolder.MyMusic -> /data/user/0/App.App/files/Music
  • Android.OS.Environment.DirectoryMusic -> /Music

None of this offer, what i wanted.I tried writing to the /storage/emulated/0/Music/ which did the job, but i dont think this path is stable.

Anyone knows how can i get the music folder path programmatically ? Im coding in C# using xamarin.android.

David Barishev
  • 534
  • 7
  • 30

1 Answers1

2

I used this code to get access to my Music Folder

public void StartPlayer(String filePath)
    {

     string Mp3Path = Path.Combine("/sdcard/"+
 Android.OS.Environment.DirectoryMusic,
    filePath);
        if (player == null)
        {
            player = new MediaPlayer();
        }

            player.Reset();
            player.SetDataSource(Mp3Path);
            player.Prepare();
            player.Start();

    }

The sdcard shortcut works great for me, hope it works for you too ^^