Xamarin.Forms MediaElement First Look

One of the best new features to be released on the Xamarin.Forms 4.5 version is the new MediaElement without doubt, I was waiting for this for a while, now Im really happy to have a video player as a builtin Xamarin.Forms control, lets see how this control works and how you can start adding it into your apps.


As you can see now this control is in preview state some features are working partially others need to be improved.

Now lets review the API and divide them in 3, properties, methods and event handlers(callbacks)

1. Properties


- Aspect Aspect
This property allow us to configure the visual aspect of the video with one of the following values AspectFit(default), AspectFill or Fill, same as we use for the Image control.

- bool AutoPlay
This property allows the player to start playing when the Source property is set, the property is set to "true" by default.

- double BufferingProgress
Returns the percentage of buffering of the current video source.

- bool CanSeek
Returns true if the player contains a valid video source otherwise false.

- MediaElementState CurrentState
Returns the current video player state, the possible values are Closed, Opening, Buffering, Playing, Pause or Stopped.

- TimeSpan? Duration
Returns the current video duration in case of an invalid Source it will return a null value.

- bool IsLooping
Get or Set whether the player will loop the current video.

- bool KeepScreenOn
Get or Set whether the screen will remains on while the player is playing.

- bool ShowPlaybackControls
Get or Set if the player will show the default video playback controls, in case that you want to create your own controls set as false.

- TimeSpan Position
Returns the current player position.

- MediaSource Source
Get or set the current media source right now it supports local path and web based videos.

- int VideoHeight
Returns the current video height in pixels.

- int VideoWidth
Returns the current video width in pixels.

- double Volume
Get or set the current player volume it can be between 0 and 1.

2. Methods


- void Play()
Allow to set current state as Playing.

- void Pause()
Allow to set current state as Pause.

- void Stop()
Allow to set current state as Stopped.

3. Event Handlers


- MediaEnded
Indicates when a video has reached end.

- MediaFailed
Indicated an error while loading a video.

- MediaOpened
Indicates when a video has loaded successfully.

- SeekCompleted
Indicates that the seek task was completed.

Usage:


First of all you need to install the latests Xamarin.Forms preview package as of today is 4.5.0.282-pre4

Since the control is on preview you'll need to property add control flag prior to use it the static constructor or the default constructor of your main Application is a good place to have it, Example:

After that you can use it on your xaml or cs, here an example of usage:





Limitations / Known Issues


Position property currently is not working "live" the property its only updated is the user perform a seek request.

Volume binding property isn't now working properly on iOS causing some crashes / UI locks while updating it.

Some properties are not working with direct bindings in case that you need to access them you'll need to reference direct from the control instance those properties are CurrentState, BufferingProgress, Duration, Position, VideoHeight & VideoWidth.

Github Demo Source Code


https://github.com/AlejandroRuiz/MediaElementPreview

Comentarios

  1. According to the docs, UWP is supported (woot) https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/mediaelement

    ResponderEliminar
  2. Hi, there still a gap in sound files (like white noise) on islooping on Android?

    ResponderEliminar
  3. Did you know there is a 12 word sentence you can speak to your man... that will trigger deep emotions of love and impulsive attraction for you deep inside his chest?

    That's because hidden in these 12 words is a "secret signal" that fuels a man's instinct to love, idolize and look after you with all his heart...

    =====> 12 Words Will Trigger A Man's Desire Instinct

    This instinct is so hardwired into a man's genetics that it will drive him to try harder than ever before to take care of you.

    Matter of fact, triggering this dominant instinct is absolutely important to having the best possible relationship with your man that as soon as you send your man one of these "Secret Signals"...

    ...You will soon notice him expose his soul and mind for you in such a way he haven't experienced before and he will recognize you as the only woman in the universe who has ever truly interested him.

    ResponderEliminar

Publicar un comentario

Entradas populares