UWP将系统媒体传输控件绑定到XAML媒体传输控件 [英] UWP Binding system media transport controls to XAML media transport controls
问题描述
是否可以通过后台媒体播放器绑定系统媒体传输控件:
Is there any way to bind system media transport controls from background media player:
BackgroundMediaPlayer.Current.SystemMediaTransportControls
添加到xaml中的媒体传输控件:
to media transport controls added in xaml:
<MediaTransportControls Name="foregroundMediaControl" HorizontalAlignment="Left" Margin="10,504,0,0" VerticalAlignment="Top" Width="340" IsVolumeButtonVisible="False" IsVolumeEnabled="False" IsZoomButtonVisible="False" IsZoomEnabled="False" IsSeekEnabled="True" IsFullWindowEnabled="False" IsFullWindowButtonVisible="False" IsAccessKeyScope="True" IsNextTrackButtonVisible="True" IsPreviousTrackButtonVisible="True" IsTextScaleFactorEnabled="False" UseSystemFocusVisuals="False" Height="101"/>
是否为两个传输控件都复制了代码并设置了处理程序?我想使用BackgroundMediaPlayer播放音乐,并能够在应用程序处于前景状态时使用媒体传输控件来控制音乐,而在应用程序处于背景状态时能够使用系统媒体传输控件来控制音乐. 希望你能理解:)
Without duplicating the code and setting handlers for both transport controls? I would like to play music with BackgroundMediaPlayer and be able to control it using media transport controls when app is in foreground and using system media transport controls when app is in background. Hope you understood :)
推荐答案
我想使用BackgroundMediaPlayer播放音乐,并且能够在应用程序处于前景状态时使用媒体传输控件来控制音乐,而在应用程序处于背景状态时能够使用系统媒体传输控件来控制音乐.
I would like to play music with BackgroundMediaPlayer and be able to control it using media transport controls when app is in foreground and using system media transport controls when app is in background.
我认为您可能会误解什么是背景音频.
I think you may misunderstand what Background audio is.
For Windows 10, version before 1607, you can refer to the Legacy background media playback, background playback consists of two processes: App UI and client logic(foreground), background playback task. As you know, the background task communicates with the system through System Media Transport Controls. And in the foreground, it actually also uses System Media Transport Controls to control the MediaPlayer
, there is no need to put another MediaElement
in the foreground, otherwise the MediaPlayer
and MeidaElement
will play the same source together in the foreground together. In another word, there is no need to bind system media transport controls to XAML media transport controls. You can check the diagram of how the system is designed in the document. And in this time, only background audio is supported, background video is not implemented.
从Windows 10版本1607 开始,对媒体播放API进行了重大改进.现在,背景是简化的单进程设计,并且它自动与系统媒体传输控制集成.为了利用这些改进,建议的播放媒体的最佳实践是使用MediaPlayer
类而不是MediaElement
进行媒体播放.因此,也无需将系统媒体传输控件绑定到XAML媒体传输控件.这次,非常令人惊讶的是,MediaPlayer
支持视频.您可以参考使用MediaPlayer播放音频和视频.
Starting with windows 10, version 1607, significant improvements were made to the media playback APIs. Now the background is a simplified single-process design and it automatically integrates with the System Media Transport Control. And to take advantage of these improvements, the recommended best practice for playing media is to use the MediaPlayer
class instead of MediaElement
for media playback. Therefore, there is also no need to bind system media transport controls to XAML media transport controls. And in this time, big surprise, video is supported with MediaPlayer
. You can refer to Play audio and video with MediaPlayer.
这篇关于UWP将系统媒体传输控件绑定到XAML媒体传输控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!