我正在尝试在后台播放声音,但仅在我的alt选项卡停止播放时才在前景播放...

snd = new MediaElement();
snd.AudioCategory = Windows.UI.Xaml.Media.AudioCategory.BackgroundCapableMedia;
StorageFolder folder = await Package.Current.InstalledLocation.GetFolderAsync("Assets");
StorageFile file = await folder.GetFileAsync("hey.mp3");
var stream = await file.OpenAsync(FileAccessMode.Read);
snd.SetSource(stream, file.ContentType);
snd.Play();

最佳答案

这是来自MSDN的Background Audio in WinRT with C#的示例

10-08 04:57