Xamarin c#SetLooping缺失

时间:2017-09-07 11:09:27

标签: c# android xamarin.android method-missing

我是编程新手,这是我在c#xamarin的第一个项目。我想在MediaPlayer上设置循环,但在Android.Media中缺少SetLooping方法。 我正在使用Visual Studio 2017社区。这是我的代码。 提前感谢任何反馈: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();
        }

1 个答案:

答案 0 :(得分:2)

SetLooping方法被映射为Xamarin.Android中的属性,您应该使用Looping属性。看看:Android.Media.MediaPlayer.Looping Property

在您的代码上试试这个

   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();
        music.Looping = true;
    }