Windows应用商店应用背景音乐不循环,无法更改音量

时间:2014-02-19 15:30:56

标签: c# audio windows-store-apps

我有很多页面的项目。

  • 我有1个背景音乐,每个页面都有几个音频。
  • 在主页上,背景音乐的音量必须为%100
  • 导航到其他页面时背景音乐音量会减少。 (%60)
  • 和背景音频必须循环。

在app.xaml.cs

public class MediaElementCommon
    {
        private static MediaElementCommon instance;
        private MediaElement _element = new MediaElement();

        private MediaElementCommon() { }

        public static MediaElementCommon Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new MediaElementCommon();
                }
                return instance;
            }
        }

        public MediaElement GetElement()
        {
            return _element;
        }


public  async Task PlayBGAudio()
    {
        //this.volume = volume;
        var package = Windows.ApplicationModel.Package.Current;
        var installedLocation = package.InstalledLocation;
        var storageFile = await installedLocation.GetFileAsync("Assets\\arkaplan.mp3");
        if (storageFile != null)
        {
            var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);
            MediaElementCommon.Instance.GetElement().SetSource(stream, storageFile.ContentType);
            //MediaElementCommon.Instance.GetElement().Volume =100;
            //MediaElementCommon.Instance.GetElement().IsLooping = true;
            MediaElementCommon.Instance.GetElement().Play();
            MediaElementCommon.Instance.GetElement().MediaEnded += new RoutedEventHandler(BGAudio_MediaEnded);

        }
    }

    private void BGAudio_MediaEnded(object sender, RoutedEventArgs e)
    {
        MediaElementCommon.Instance.GetElement().Position = TimeSpan.Zero;
        MediaElementCommon.Instance.GetElement().Play();
    }

public App()
    {
        PlayBGAudio();
        this.InitializeComponent();

        this.Suspending += OnSuspending;

    }

我改变了循环和音量属性但没有改变。

0 个答案:

没有答案