Issue
I added the *.mp3 file to the Resources/raw and don't know how to use it.
I want to start playing it in a media player:
public void Play()
{
Stop();
_player.Reset();
string uri = "android.resource://Songer.Android/Resources/raw/test.mp3";
_player.SetDataSource(uri);
_player.Prepare();
_player.Start();
}
But it does not find my file.
Solution
Play the mp3 file from resource folder, you could try the code below.
MediaPlayer mediaPlayer = MediaPlayer.Create(this, Resource.Raw.BuckBunnySound);
mediaPlayer.Start();
The code you used works well on Assets folder.
var player = new MediaPlayer();
var fd = global::Android.App.Application.Context.Assets.OpenFd("BuckBunny.mp3");
player.Prepared += (s, e) =>
{
player.Start();
};
player.SetDataSource(fd.FileDescriptor, fd.StartOffset, fd.Length);
player.Prepare();
Answered By - Wendy Zang - MSFT
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.