UWP Binding system media transport controls to XAML media transport controls

爱⌒轻易说出口 提交于 2019-12-25 04:26:36

问题


Is there any way to bind system media transport controls from background media player:

BackgroundMediaPlayer.Current.SystemMediaTransportControls

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"/>

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 :)


回答1:


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.

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.



来源:https://stackoverflow.com/questions/39318800/uwp-binding-system-media-transport-controls-to-xaml-media-transport-controls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!