Reputation: 381
public override void OnActivityCreated (Bundle savedInstanceState)
{
base.OnActivityCreated (savedInstanceState);
StartMedia(source);
}
public void StartMedia(string url_string)
{
player = new MediaPlayer ();
player.SetDataSource (url_string);
//player.Prepare ();
player.Start ();
}
It don't run. don't run, don't listen anything. I have debug but I don't see it though over void StartMedia
StartMedia(mListData[mPosition].stream_url+"?client_id="+clienId);
}
public async void StartMedia(string url_string)
{
player = new MediaPlayer ();
player.SetVolume (100, 100);
player.SetAudioStreamType (Stream.Music);
await player.SetDataSourceAsync(Android.App.Application.Context,Android.Net.Uri.Parse(url_string));
player.PrepareAsync ();
player.Start ();
}
When the audio to play is included as a resource, the method can be used to set up the data source to the audio file and prepare the player for playback automatically.
Upvotes: 3
Views: 7946
Reputation: 74164
I use internet source...
var mp3TestFile = "https://archive.org/download/testmp3testfile/mpthreetest.mp3";
player = new MediaPlayer();
player.SetAudioStreamType(Stream.Music);
await player.SetDataSourceAsync(ApplicationContext, Android.Net.Uri.Parse(mp3TestFile));
player.Prepare();
player.Start();
Background Audio Streaming with Xamarin.Android
Upvotes: 1
Reputation: 194
Add the Audio file you need to play in raw folder. For example it is "MyAudio.mp3"
MediaPlayer player;
public bool StartMedia ()
{
player = MediaPlayer.Create (this, Resource.Raw.MyAudio);
player.Start ();
return true;
}
Upvotes: 6