简体   繁体   中英

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

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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