C# Windows应用商店应用程序背景音乐未循环,无法更改音量
我有很多页的项目C# Windows应用商店应用程序背景音乐未循环,无法更改音量,c#,audio,windows-store-apps,C#,Audio,Windows Store Apps,我有很多页的项目 我有一个背景音乐和每一页有夫妇的音频 在主页上,背景音乐的音量必须为100% 当导航到其他页面时,背景音乐音量将减小。(%60) 和背景音频必须循环 在app.xaml.cs中 public class MediaElementCommon { private static MediaElementCommon instance; private MediaElement _element = new MediaElement();
- 我有一个背景音乐和每一页有夫妇的音频李>
- 在主页上,背景音乐的音量必须为100%
- 当导航到其他页面时,背景音乐音量将减小。(%60)
- 和背景音频必须循环
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-1之间缩放的,我在代码中写了%100,它的意思是1:),但你说的是
//MediaElementCommon.Instance.GetElement().Volume=100代码>(显然已注释),但您是否正确实现了该开关?我尝试了0.6,但没有任何更改。还尝试了循环部分,但也不起作用。请尝试将“RealTimePlayback”设置为“true”。这也可能不是播放背景音乐的正确方式。是否可以改为使用概述的方法?您可以有两份音乐副本,一份60%和一份100%音量,只需根据当前视图切换播放哪一份即可。您只需在每次视图更改时更改位置,尽管我不知道这会有多完美。