简体   繁体   中英

UWP, For mediaplayerelement, how to override build in play button?

Basically, I am using mediaplayerelement, and with CustomMediaTransportControls with some custom buttons, I have one issue need to solve:

The media is set to autoplay, so when source is set, the playing starts, when pause button is clicked, the playing pauses, and the button changes to play state, now when play button is clicked, I want add a function before the playing starts, to first refresh and get a new source then play.

I really don't want to create my own media control if possible, so basically using build in transport control, just some how override playbutton_click, is this doable?

Use PlaybackStateChanged event and check for PlaybackState

public MainPage()
{
    this.InitializeComponent();
    MediaPlayerElementName.MediaPlayer.PlaybackSession.PlaybackStateChanged += PlaybackSession_PlaybackStateChanged;
}

bool isFirst = true;
private void PlaybackSession_PlaybackStateChanged(MediaPlaybackSession sender, object args)
{
    if (sender.PlaybackState == MediaPlaybackState.Playing)
    {
        if (!isFirst)
        {
            //Set your New source
            isFirst = true;
        }
        else
            isFirst = false;
    }
}

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