I'm novice in programming and this is my first project ever in c# xamarin. I want to set loop on that MediaPlayer but SetLooping method is missing in Android.Media. I'm using Visual Studio 2017 Community. Here is my code. Thanks in advance for any feedback :D
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Media;
using Android.Content;
using Android.Preferences;
using Android.Views.Animations;
namespace App2
{
[Activity(Label = "FirstApp 1.34", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
MediaPlayer music;
protected override void OnPause()
{
base.OnPause();
music.Pause();
}
protected override void OnDestroy()
{
music.Release();
base.OnDestroy();
}
protected override void OnResume()
{
music.Start();
base.OnResume();
}
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
music = MediaPlayer.Create(this, Resource.Raw.bgsound);
music.SetVolume(0.7f, 0.7f);
music.Start();
}
SetLooping
method is mapped as a property in Xamarin.Android and you should use theLooping
property instead. Take a look at: Android.Media.MediaPlayer.Looping PropertyTry this on your code