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:
Closedindicates that theMediaElementcontains no media.Openingindicates that theMediaElementis validating and attempting to load the specified source.Bufferingindicates that theMediaElementis loading the media for playback. ItsPositionproperty does not advance during this state. If theMediaElementwas playing video, it continues to display the last displayed frame.Playingindicates that theMediaElementis playing the media source.Pausedindicates that theMediaElementdoes not advance itsPositionproperty. If theMediaElementwas playing video, it continues to display the current frame.Stoppedindicates that theMediaElementcontains media but it is not being played or paused. ItsPositionproperty is 0 and does not advance. If the loaded media is video, theMediaElementdisplays 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,OpeningorBufferingstates. - The Android renderer never sets the
ClosedorOpeningstates. - 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
MediaElementStateenum be reduced to members that are all implemented on our primary platforms? - Should the
CurrentStateproperty 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