David Barishev
David Barishev

Reputation: 544

How to get the music folder path in xamarin.android?

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:

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.

Upvotes: 1

Views: 1393

Answers (1)

Walid Hafid
Walid Hafid

Reputation: 21

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 ^^

Upvotes: 2

Related Questions