简体   繁体   English

如何在UWP的后台播放音频

[英]How to play audio in the background of a UWP

I created a media player app using UWP for Windows 10. Currently I cannot play any audio in the background, when I minimize my media player window the audio stops playing and resumes when I maximize the window. 我使用适用于Windows 10的UWP创建了一个媒体播放器应用程序。当前,我无法在后台播放任何音频,当我最小化媒体播放器窗口时,音频会停止播放,并在最大化窗口时恢复。 This is my media element XAML code I used: 这是我使用的媒体元素XAML代码:

<MediaElement x:Name="PlayerElement" Height="532" Width="829" 
                            AreTransportControlsEnabled="True" Stretch="Uniform" HorizontalAlignment="Center" 
                            VerticalAlignment="Center" PosterSource="/Images/Logo3.png" 
                          AutoPlay="True" MediaEnded="PlayNewSong" Margin="0,0,-9,0" AudioCategory="BackgroundCapableMedia"/>

I thought the AudioCategory property would solve my problem, but unfortunately it doesn't. 我以为AudioCategory属性可以解决我的问题,但不幸的是,它不能解决问题。 Any help would be appreciated. 任何帮助,将不胜感激。

Check this official sample collection from microsoft WindowsUniversalSamples 从Microsoft WindowsUniversalSamples检查此官方样本集合

You can pull BackgroundMediaPlayback folder for sample project you need. 您可以提取BackgroundMediaPlayback文件夹用于所需的示例项目。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM