Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Android,iOS,UWP,WPF] MediaElement control #3482

Merged
merged 110 commits into from
Jan 29, 2020
Merged

[Android,iOS,UWP,WPF] MediaElement control #3482

merged 110 commits into from
Jan 29, 2020

Conversation

peterfoot
Copy link
Contributor

@peterfoot peterfoot commented Aug 3, 2018

Description of Change

Adds a simple MediaElement control to Xamarin Forms. The control can play online and local content (app package via ms-appx uris and app data folder using ms-appdata) along with file uris. There are full renderers for Android, iOS and UWP and a limited renderer for WPF.
A page has been added to the ControlGallery project to demo the control but there are no automated tests currently.

Issues Resolved

API Changes

Added:

  • MediaElement class

    • Aspect property

    • AutoPlay property

    • BufferingProgress property

    • CanSeek property

    • CurrentState property

    • Duration property

    • IsLooping property

    • KeepScreenOn property

    • Position property

    • ShowsPlaybackControls property

    • Source property

    • VideoHeight property

    • VideoWidth property

    • Volume property

    • Play method

    • Pause method

    • Stop method

    • MediaEnded event

    • MediaFailed event

    • MediaOpened event

    • SeekCompleted event

  • MediaElementState enum

  • MediaSource class

    • FromFile method
    • FromUri method
  • FileMediaSource class

    • File property
  • UriMediaSource class

    • Uri property

The API is largely unchanged from the original InTheHand.Forms.MediaElement except Stretch is replaced with the existing Aspect enum used by the Image control.

Platforms Affected

  • Core/XAML (all platforms)
  • iOS
  • Android*
  • UWP
  • WPF**

*Android will not render video stretched to fill (Aspect.Fill) and so will default to the same behaviour as Aspect.AspectFit adding letter-boxing if necessary.
**WPF renderer doesn't currently support all functionality - ShowsPlaybackControls has not equivalent functionality in underlying control. Currently Position change events don't function.

Behavioral/Visual Changes

N/A This is a new control

PR Checklist

  • Has automated tests
  • Rebased on top of the target branch at time of PR
  • Changes adhere to coding standard

@dnfclas
Copy link

dnfclas commented Aug 3, 2018

CLA assistant check
All CLA requirements met.

…o that can determine when value is not present.

Added CanSeek property to indicate when Position property can be set.
Added support for KeepScreenOn to WPF renderer.
Improved ControlGallery page with separate Play/Pause/Stop buttons and label to display current state
@xamarin-release-manager xamarin-release-manager added the API-change Heads-up to reviewers that this PR may contain an API change label Aug 6, 2018
@jfversluis
Copy link
Member

Just wanted to say; awesome work!

@RadwanIbrahim
Copy link

wonderful work thank you very much, I have one question can this play audio too

@peterfoot
Copy link
Contributor Author

@RadwanIbrahim yes you can play any audio format supported on the underlying platform e.g. mp3 etc

@kingces95 kingces95 self-assigned this Aug 21, 2018
@xamarin-release-manager xamarin-release-manager added the API-change Heads-up to reviewers that this PR may contain an API change label Aug 21, 2018
@rmarinho
Copy link
Member

Hi @peterfoot can we rebase/merge master? thanks

…r to workaround issue with dispose when using on modal pages.
@peterfoot
Copy link
Contributor Author

@rmarinho will try again to rebase tomorrow as I ran into errors running it today.


namespace Xamarin.Forms.Platform.Android
{
public sealed class MediaElementRenderer : FrameLayout, IVisualElementRenderer, IViewRenderer, IEffectControlProvider, MediaPlayer.IOnCompletionListener, MediaPlayer.IOnInfoListener, MediaPlayer.IOnPreparedListener, MediaPlayer.IOnErrorListener
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@samhouts do we need this to be sealed? I realize it's experimental but seeing as how it's experimental being able to extend the renderer seems even more important because of the possibility of needing to add behavior or work around bugs

@PureWeen
Copy link
Contributor

@peterfoot can you give me access to make some changes so I can fix the compile errors?

@peterfoot
Copy link
Contributor Author

@PureWeen I fixed those two but you should have access now if you need to make any other changes

@rmarinho
Copy link
Member

@peterfoot needs rebase or merge master

@samhouts
Copy link
Member

Failing tests appear to be unrelated and are passing locally.

DRUMROLL PLEASE

@samhouts samhouts merged commit b486522 into xamarin:master Jan 29, 2020
@abdu292
Copy link

abdu292 commented Jan 29, 2020

@peterfoot Amazing. Congratulations!!! One question though. How to enable lock screen notifications and to control the player from notification screen?
(planning to test my custom implementation of audio player with this one), thanks in advance!

@peterfoot
Copy link
Contributor Author

@abdu292 This isn't supported currently. It will require some investigation to find a cross-platform way of exposing this but it's a good idea for a future update!

@abdu292
Copy link

abdu292 commented Jan 29, 2020

thanks @peterfoot. Eagerly waiting for this to be a part. MediaManager plugin has something implemented, which you may have a look at, to get some idea on this.

@davidbuckleyni
Copy link

@peterfoot Congrats Peter just saw the merge request cant wait get this down and play with it. Planning on making a running app and music is one of its features. Do we no what live version this will go in to or will it be pre-release for now.

@martijn00
Copy link
Contributor

@abdu292 it's never going to happen. MediaManager has a dependency on Exoplayer and I don't believe Forms is going to do that. Better use MediaManager for everything media related ;)

@abdu292
Copy link

abdu292 commented Jan 29, 2020

thanks @martijn00 . I meant to say to look at the media manager code just to get an idea and not to copy the exact code. Media manager uses Exo for android, that doesn't mean Notifications can't be integrated with simple Media player (as you must know). Player and notifications are two different things, though exo has a nice way of integrating notification. You/Baseflow have done an excellent job with MediaManager. I have been using MediaManager in the past months. However I ran in to multiple issues - may be my specific use cases - and started writing my own player & notification implementations. Also, when I looked at the history of release it's really scary. It doesn't have a consistent maintaining history, release are not at all consistent (Yes, I understand its open source and releases don't have to be consistent), some comments in the github issues give an impression to the developers that the owner is angry/owner is not interested to maintain the repo any more, etc.
If a feature is natively available in Xamarin.Forms, it is unlikely that a developer will go for a third party plugin if he/she gets all the things he/she needs.
thanks for all your work on the MediaManager. I'll definitely look back to this once it hits its first 1.x release. Regards!

PureWeen pushed a commit that referenced this pull request Feb 5, 2020
* MediaElement and iOS/Android/UWP renderers.

* Added basic WPF renderer. Fixed sizing issue on UWP renderer. Added sample page to ControlGallery app

* MediaEnded event on UWP. Source Uri convert ms-appx to pack:// uri scheme on WPF

* code style fixes

* resolving conflicts

* Following discussion on PR made NaturalDuration a nullable TimeSpan so that can determine when value is not present.
Added CanSeek property to indicate when Position property can be set.
Added support for KeepScreenOn to WPF renderer.
Improved ControlGallery page with separate Play/Pause/Stop buttons and label to display current state

* coding style fixes

* coding style fixes 2

* Improved media controls on demo page. Renderer enhancements for Android and iOS

* Improved logic around media metadata in iOS renderer.
Switched to https video uri to allow playback in iOS. Increased media control button sizes

* Improved parsing of ms-appdata uris supporting both the local and temp folders

* Removed redundant Debug.WriteLines. Removed XML docs from MediaElement and MediaElementState types.

* Bug fix for iOS MediaElement.Source Uri escape handling

* Adding MediaElement fast renderer for Android

* Rearchitecting the Element/Renderer connectivity. New WPF,UAP and Android FastRenderer complete. Still requires Android classic renderer and iOS renderer...

* More MediaElement renderer development. Converted iOS to a FastRenderer

* Latest android renderer

* Android renderer fix for StopPlayback reusability. MetadataRetreiver now loaded async.

* Added an IMediaElementController property to Android renderers to simplify code.

* Simplified Aspect property

* Changed AreTransportControlsEnabled to ShowsPlaybackControls. Removed commented-out code.

* merging

* merging

* added mediaelementrenderer back

* support for polling the position property. Added timer to demopage to poll for position.

* Fixed scaling issue on iOS and background color

* Renderer code review issues

* Implementing MediaSource (ImageSource pattern) to replace Uris. Other code cleaning fixes.

* Hooked up MediaSource and kept uri custom schema logic

* Moved all the "callback" methods to the IMediaElementController interface so they are not publicly exposed on the MediaElement. Removed HttpHeaders and associated code for v1 release. Other code tidying.

* Code review feedback

* Integrated unit tests. Added support for inherited binding on MediaSource.

* Additional Windows file path test. Fix for UWP renderer to check if Control is released

* Fix for FormsVideoView metadata causing aspect issues. Simplified Android FastRenderer to correctly handle VideoView lifetime.

* fixed merge error

* fixed merge errors

* MediaElement and iOS/Android/UWP renderers.

* Added basic WPF renderer. Fixed sizing issue on UWP renderer. Added sample page to ControlGallery app

* MediaEnded event on UWP. Source Uri convert ms-appx to pack:// uri scheme on WPF

* code style fixes

* resolving conflicts

* Following discussion on PR made NaturalDuration a nullable TimeSpan so that can determine when value is not present.
Added CanSeek property to indicate when Position property can be set.
Added support for KeepScreenOn to WPF renderer.
Improved ControlGallery page with separate Play/Pause/Stop buttons and label to display current state

* coding style fixes

* coding style fixes 2

* Improved media controls on demo page. Renderer enhancements for Android and iOS

* Improved logic around media metadata in iOS renderer.
Switched to https video uri to allow playback in iOS. Increased media control button sizes

* Improved parsing of ms-appdata uris supporting both the local and temp folders

* Removed redundant Debug.WriteLines. Removed XML docs from MediaElement and MediaElementState types.

* Bug fix for iOS MediaElement.Source Uri escape handling

* Adding MediaElement fast renderer for Android

* Rearchitecting the Element/Renderer connectivity. New WPF,UAP and Android FastRenderer complete. Still requires Android classic renderer and iOS renderer...

* More MediaElement renderer development. Converted iOS to a FastRenderer

* Latest android renderer

* Android renderer fix for StopPlayback reusability. MetadataRetreiver now loaded async.

* Added an IMediaElementController property to Android renderers to simplify code.

* Simplified Aspect property

* Changed AreTransportControlsEnabled to ShowsPlaybackControls. Removed commented-out code.

* merging

* support for polling the position property. Added timer to demopage to poll for position.

* Fixed scaling issue on iOS and background color

* Renderer code review issues

* Implementing MediaSource (ImageSource pattern) to replace Uris. Other code cleaning fixes.

* Hooked up MediaSource and kept uri custom schema logic

* Moved all the "callback" methods to the IMediaElementController interface so they are not publicly exposed on the MediaElement. Removed HttpHeaders and associated code for v1 release. Other code tidying.

* Code review feedback

* Integrated unit tests. Added support for inherited binding on MediaSource.

* Additional Windows file path test. Fix for UWP renderer to check if Control is released

* Fix for FormsVideoView metadata causing aspect issues. Simplified Android FastRenderer to correctly handle VideoView lifetime.

* fixed merge error

* manual merge fixes

* Fixed missing FileMediaSourceConverter

* Fixed merge issue with iOS project file

* Clarification to WPF Source Uri exception message

* Changed iOS local path to the Library path as this is not user visible or synchronised with iCloud. Fix for breaking change in WeakEventManager

* Added Volume property

* Fixes for code-review feedback

* Optimised iOS renderer to remove a view layer

* fixes to resolve possible rotation bug

* Moved ms-appdata parsing to shared location.

* fixed codesign error

* Fix for issue on Android where control may show black screen prior to video playing - now respects backgroundcolor property

* Renamed conflicting extensions class

* Add experimental flag; remove slow renderer

* Update MediaElementDemoPage.cs

* Update MediaElementRenderer.cs

* Update MediaElementRenderer.cs

* Porting latest renderer updates. iOS re-written as a non-fast renderer to workaround issue with dispose when using on modal pages.

* Fixed protected member in sealed class issue

Co-authored-by: Rui Marinho <[email protected]>
Co-authored-by: Samantha Houts <[email protected]>
fixes #1692
PureWeen added a commit that referenced this pull request Feb 5, 2020
* MediaElement and iOS/Android/UWP renderers.

* Added basic WPF renderer. Fixed sizing issue on UWP renderer. Added sample page to ControlGallery app

* MediaEnded event on UWP. Source Uri convert ms-appx to pack:// uri scheme on WPF

* code style fixes

* resolving conflicts

* Following discussion on PR made NaturalDuration a nullable TimeSpan so that can determine when value is not present.
Added CanSeek property to indicate when Position property can be set.
Added support for KeepScreenOn to WPF renderer.
Improved ControlGallery page with separate Play/Pause/Stop buttons and label to display current state

* coding style fixes

* coding style fixes 2

* Improved media controls on demo page. Renderer enhancements for Android and iOS

* Improved logic around media metadata in iOS renderer.
Switched to https video uri to allow playback in iOS. Increased media control button sizes

* Improved parsing of ms-appdata uris supporting both the local and temp folders

* Removed redundant Debug.WriteLines. Removed XML docs from MediaElement and MediaElementState types.

* Bug fix for iOS MediaElement.Source Uri escape handling

* Adding MediaElement fast renderer for Android

* Rearchitecting the Element/Renderer connectivity. New WPF,UAP and Android FastRenderer complete. Still requires Android classic renderer and iOS renderer...

* More MediaElement renderer development. Converted iOS to a FastRenderer

* Latest android renderer

* Android renderer fix for StopPlayback reusability. MetadataRetreiver now loaded async.

* Added an IMediaElementController property to Android renderers to simplify code.

* Simplified Aspect property

* Changed AreTransportControlsEnabled to ShowsPlaybackControls. Removed commented-out code.

* merging

* merging

* added mediaelementrenderer back

* support for polling the position property. Added timer to demopage to poll for position.

* Fixed scaling issue on iOS and background color

* Renderer code review issues

* Implementing MediaSource (ImageSource pattern) to replace Uris. Other code cleaning fixes.

* Hooked up MediaSource and kept uri custom schema logic

* Moved all the "callback" methods to the IMediaElementController interface so they are not publicly exposed on the MediaElement. Removed HttpHeaders and associated code for v1 release. Other code tidying.

* Code review feedback

* Integrated unit tests. Added support for inherited binding on MediaSource.

* Additional Windows file path test. Fix for UWP renderer to check if Control is released

* Fix for FormsVideoView metadata causing aspect issues. Simplified Android FastRenderer to correctly handle VideoView lifetime.

* fixed merge error

* fixed merge errors

* MediaElement and iOS/Android/UWP renderers.

* Added basic WPF renderer. Fixed sizing issue on UWP renderer. Added sample page to ControlGallery app

* MediaEnded event on UWP. Source Uri convert ms-appx to pack:// uri scheme on WPF

* code style fixes

* resolving conflicts

* Following discussion on PR made NaturalDuration a nullable TimeSpan so that can determine when value is not present.
Added CanSeek property to indicate when Position property can be set.
Added support for KeepScreenOn to WPF renderer.
Improved ControlGallery page with separate Play/Pause/Stop buttons and label to display current state

* coding style fixes

* coding style fixes 2

* Improved media controls on demo page. Renderer enhancements for Android and iOS

* Improved logic around media metadata in iOS renderer.
Switched to https video uri to allow playback in iOS. Increased media control button sizes

* Improved parsing of ms-appdata uris supporting both the local and temp folders

* Removed redundant Debug.WriteLines. Removed XML docs from MediaElement and MediaElementState types.

* Bug fix for iOS MediaElement.Source Uri escape handling

* Adding MediaElement fast renderer for Android

* Rearchitecting the Element/Renderer connectivity. New WPF,UAP and Android FastRenderer complete. Still requires Android classic renderer and iOS renderer...

* More MediaElement renderer development. Converted iOS to a FastRenderer

* Latest android renderer

* Android renderer fix for StopPlayback reusability. MetadataRetreiver now loaded async.

* Added an IMediaElementController property to Android renderers to simplify code.

* Simplified Aspect property

* Changed AreTransportControlsEnabled to ShowsPlaybackControls. Removed commented-out code.

* merging

* support for polling the position property. Added timer to demopage to poll for position.

* Fixed scaling issue on iOS and background color

* Renderer code review issues

* Implementing MediaSource (ImageSource pattern) to replace Uris. Other code cleaning fixes.

* Hooked up MediaSource and kept uri custom schema logic

* Moved all the "callback" methods to the IMediaElementController interface so they are not publicly exposed on the MediaElement. Removed HttpHeaders and associated code for v1 release. Other code tidying.

* Code review feedback

* Integrated unit tests. Added support for inherited binding on MediaSource.

* Additional Windows file path test. Fix for UWP renderer to check if Control is released

* Fix for FormsVideoView metadata causing aspect issues. Simplified Android FastRenderer to correctly handle VideoView lifetime.

* fixed merge error

* manual merge fixes

* Fixed missing FileMediaSourceConverter

* Fixed merge issue with iOS project file

* Clarification to WPF Source Uri exception message

* Changed iOS local path to the Library path as this is not user visible or synchronised with iCloud. Fix for breaking change in WeakEventManager

* Added Volume property

* Fixes for code-review feedback

* Optimised iOS renderer to remove a view layer

* fixes to resolve possible rotation bug

* Moved ms-appdata parsing to shared location.

* fixed codesign error

* Fix for issue on Android where control may show black screen prior to video playing - now respects backgroundcolor property

* Renamed conflicting extensions class

* Add experimental flag; remove slow renderer

* Update MediaElementDemoPage.cs

* Update MediaElementRenderer.cs

* Update MediaElementRenderer.cs

* Porting latest renderer updates. iOS re-written as a non-fast renderer to workaround issue with dispose when using on modal pages.

* Fixed protected member in sealed class issue

Co-authored-by: Rui Marinho <[email protected]>
Co-authored-by: Samantha Houts <[email protected]>
fixes #1692

Co-authored-by: Peter Foot <[email protected]>
@davidbuckleyni
Copy link

Might be dumb question been away from xammy for a while how does one turn on the feature flag what file ???

@jfversluis
Copy link
Member

No problem @davidbuckleyni!

You can find that info on the Docs for the actual control. In this case right under the first screenshot here.

I have a somewhat more generic blog post about it here.

@samhouts samhouts modified the milestones: 4.3.0, 4.5.0 Apr 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[F100] MediaPlayer View