How do I determine if MediaElement is playing?

前端 未结 8 2190
闹比i
闹比i 2021-01-01 09:44

Seems simple enough, but I cannot figure out any way to determine what the state of a MediaElement is. There are various properties for some states (such as IsBuffering) but

相关标签:
8条回答
  • 2021-01-01 10:40

    For the WPF MediaElement, here is the solution/workaround I use:

    bool IsPlaying()
    {
        var pos1 = wpfMediaElement.Position;
        System.Threading.Thread.Sleep(1);
        var pos2 = wpfMediaElement.Position;
    
        return pos2 != pos1;
    }
    
    0 讨论(0)
  • 2021-01-01 10:42

    For Universal Windows 10 Platform (UWP) :

    if ( yourMediaElement.CurrentState.ToString() == "Playing" ) 
    {
        //nou yourMediaElement is playng
    }
    

    or below if you wana use an enum instead:

    if (yourMediaElement.CurrentState == MediaElementState.Playing)
    {
        //nou yourMediaElement is playng
    }
    
    0 讨论(0)
提交回复
热议问题