-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android,iOS,UWP,WPF] MediaElement control #3482
Conversation
Xamarin.Forms.Platform.Android/Renderers/MediaElementRenderer.cs
Outdated
Show resolved
Hide resolved
…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
Just wanted to say; awesome work! |
Xamarin.Forms.Platform.Android/Renderers/MediaElementRenderer.cs
Outdated
Show resolved
Hide resolved
Xamarin.Forms.Platform.Android/Renderers/MediaElementRenderer.cs
Outdated
Show resolved
Hide resolved
Xamarin.Forms.Platform.Android/Renderers/MediaElementRenderer.cs
Outdated
Show resolved
Hide resolved
Xamarin.Forms.Platform.Android/Renderers/MediaElementRenderer.cs
Outdated
Show resolved
Hide resolved
wonderful work thank you very much, I have one question can this play audio too |
@RadwanIbrahim yes you can play any audio format supported on the underlying platform e.g. mp3 etc |
Switched to https video uri to allow playback in iOS. Increased media control button sizes
...n.Forms.ControlGallery.WindowsUniversal/Xamarin.Forms.ControlGallery.WindowsUniversal.csproj
Outdated
Show resolved
Hide resolved
Xamarin.Forms.Platform.Android/Renderers/MediaElementRenderer.cs
Outdated
Show resolved
Hide resolved
Xamarin.Forms.Platform.Android/Renderers/MediaElementRenderer.cs
Outdated
Show resolved
Hide resolved
Hi @peterfoot can we rebase/merge master? thanks |
…r to workaround issue with dispose when using on modal pages.
@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 |
There was a problem hiding this comment.
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
Xamarin.Forms.Platform.Android/FastRenderers/MediaElementRenderer.cs
Outdated
Show resolved
Hide resolved
Xamarin.Forms.Platform.Android/FastRenderers/MediaElementRenderer.cs
Outdated
Show resolved
Hide resolved
@peterfoot can you give me access to make some changes so I can fix the compile errors? |
@PureWeen I fixed those two but you should have access now if you need to make any other changes |
@peterfoot needs rebase or merge master |
merge master
Failing tests appear to be unrelated and are passing locally. DRUMROLL PLEASE |
@peterfoot Amazing. Congratulations!!! One question though. How to enable lock screen notifications and to control the player from notification screen? |
@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! |
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. |
@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. |
@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 ;) |
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. |
* 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
* 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]>
Might be dumb question been away from xammy for a while how does one turn on the feature flag what file ??? |
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. |
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
FileMediaSource class
UriMediaSource class
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
*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