1

I'm working on a new app and I decided to use MediaPlayerElement to play background music and also video, But there's a problem. Also, there's the same issue on the SystemMediaTransportControls sample on Universal Windows Platform samples. In that sample, AreTransportControlsEnabled is set to False, but if you change it to True, You'll get a disabled Play/Pause button and there's no property to enable it! Even I tried to get Buttons in MediaTransportControl by their names and tried to set them Enabled, But clicking once on the play or pause button makes it disabled once again without any action.

enter image description here

Is there any solution? Regards.

EDIT: I also changed these lines to add some more buttons.

<MediaPlayerElement x:Name="mediaPlayerElement" Margin="0,0,10,0" AreTransportControlsEnabled="True" VerticalAlignment="Top">
                        <MediaPlayerElement.TransportControls>
                            <MediaTransportControls IsNextTrackButtonVisible="True" IsPreviousTrackButtonVisible="True"
                                                    IsSkipBackwardButtonVisible="True" IsSkipBackwardEnabled="True"
                                                    IsSkipForwardButtonVisible="True" IsSkipForwardEnabled="True"/>
                        </MediaPlayerElement.TransportControls>
                    </MediaPlayerElement>

Skip buttons are also disabled, Next and Previous buttons are Enabled but no action if you click on them. Same behavior also, On my app happens.

Ali NGame
  • 449
  • 3
  • 14

1 Answers1

1

MediaPlayerElement play/pause button is always disabled

The official code sample was handle the SMTC manually, so the internal play/pause button is always disabled.

If you want to use internal SMTC , please make a blank sample with above xaml code.

For example

<MediaPlayerElement
    x:Name="mediaPlayerElement"
    Margin="0,0,10,0"
    AreTransportControlsEnabled="True"
    Source="ms-appx:///Assets/hello.mp4">
    <MediaPlayerElement.TransportControls>
        <MediaTransportControls
            IsNextTrackButtonVisible="True"
            IsPreviousTrackButtonVisible="True"
            IsSkipBackwardButtonVisible="True"
            IsSkipBackwardEnabled="True"
            IsSkipForwardButtonVisible="True"
            IsSkipForwardEnabled="True" />
    </MediaPlayerElement.TransportControls>
</MediaPlayerElement>

Update

private async void Page_Drop(object sender, DragEventArgs e)
{
    var def = e.GetDeferral();
    var file = (StorageFile)(await e.DataView.GetStorageItemsAsync()).FirstOrDefault();
    EmbeddedPlayer.Source = MediaSource.CreateFromStorageFile(file);

    //await AppCore.Instance.Play(new StorageFile[] { file });
    //EmbeddedPlayer.SetMediaPlayer(AppCore.Instance.MediaPlayer);
   
    EmbeddedPlayer.MediaPlayer.Play();
    def.Complete();
}
Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
  • I know the way it handles the SMTC. even this XAML isn't working, I mean the SkipForward and SkipBackward and also play/pause buttons are still disabled. :( – Ali NGame Aug 03 '21 at 16:19
  • Yes, sure. But if I create a repro for it, It will not be so much different than the official SMTC sample of Microsoft. I want to create a Music/Video player that supports SMTC and ModernFlyouts (a store application), But ok, I will make it and upload it soon – Ali NGame Aug 04 '21 at 14:48
  • Here is the Minimal repro. If you drag and drop an mp4 file for example it will start playing. https://www.mediafire.com/file/vn8big60zj1o85r/ProplayerRepro.rar/file – Ali NGame Aug 04 '21 at 20:48
  • Your sample is not available, could you share with github? – Nico Zhu Aug 05 '21 at 01:59
  • That's strange. Surely, here you are: https://github.com/NGame1/ProplayerRepro/blob/main/ProplayerRepro.rar – Ali NGame Aug 05 '21 at 05:56
  • Ok, I got it, the problem is that you handle the smtc manually. please EmbeddedPlayer internal MediaPlayer, see above reply's update part. – Nico Zhu Aug 05 '21 at 06:19