我有很多页面的项目。
在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;
}
我改变了循环和音量属性但没有改变。