XamarinCommunityToolkit
XamarinCommunityToolkit copied to clipboard
[Bug] MediaElement inconsistent setting of CurrentState property
Description
MediaElement
includes a CurrentState
bindable property that indicates the current status of the control. This property has a default of MediaElementState.Closed
.
Here's the description of each MediaElementState
enumeration member from the UWP docs:
-
Closed
indicates that theMediaElement
contains no media. -
Opening
indicates that theMediaElement
is validating and attempting to load the specified source. -
Buffering
indicates that theMediaElement
is loading the media for playback. ItsPosition
property does not advance during this state. If theMediaElement
was playing video, it continues to display the last displayed frame. -
Playing
indicates that theMediaElement
is playing the media source. -
Paused
indicates that theMediaElement
does not advance itsPosition
property. If theMediaElement
was playing video, it continues to display the current frame. -
Stopped
indicates that theMediaElement
contains media but it is not being played or paused. ItsPosition
property is 0 and does not advance. If the loaded media is video, theMediaElement
displays the first frame.
The description of each member seems reasonable.
After looking at the renderers, I noticed that:
- The iOS renderer never sets the
Closed
,Opening
orBuffering
states. - The Android renderer never sets the
Closed
orOpening
states. - Only the UWP renderer sets all 6 states.
The doc can clarify this, but it's not ideal (the view being that the user experience shouldn't leave users scratching their heads wondering what's going on).
So after loading a video file (with AutoPlay=false), I'd expect the CurrentState
property to be Stopped
. Instead, here's what it actually is:
- iOS: Closed
- Android: Paused
- UWP: don't care
I'm hoping there isn't a good reason for the above, and that it's a bug. When you use custom transport controls you don't want to enable your Play button until the video has loaded. However, it's harder to do this when an inconsistent CurrentState
is set on each each platform. In particular you lose the elegance of having a combined Play/Pause button, where the Text is changed by a DataTrigger based on the CurrentState
value, and the ability for a DataTrigger to enable/disable buttons.
So overall I have two points:
- Should the
MediaElementState
enum be reduced to members that are all implemented on our primary platforms? - Should the
CurrentState
property have a consistent value after loading a video (but not having hit the play button)?
Any update on this issue?
I have experienced this as well, on iOS, the default "Closed" state surprised me a little bit.
I've created a repository showcasing some of the MediaElement bugs, including this one: https://github.com/ewerspej/MediaCustomTransport