Skip to content

[Proposal] Add support for local files and package resources to MediaElement #2151

@ne0rrmatrix

Description

@ne0rrmatrix

Feature name

Add support for local files and package resources to MediaElement

Link to discussion

#1989

Progress tracker

  • Android Implementation
  • iOS Implementation
  • MacCatalyst Implementation
  • Windows Implementation
  • Tizen Implementation
  • Unit Tests
  • Samples
  • Documentation

Summary

Add support for local files and package resources as a source for MediaElement.ArtworkUrl. This will add the missing support for all types of files on all device for artwork images.

Motivation

Allow developer more options to add images from more locations to use as artwork for player.

Detailed Design

API Design:

/// <summary>
	/// Backing store for the <see cref="MetadataArtworkUrl"/> property.
	/// </summary>
	public static readonly BindableProperty MetadataArtworkUrlProperty = BindableProperty.Create(nameof(MetadataArtworkSource), typeof(MediaSource), typeof(MediaElement));
/// Gets or sets the Artwork Image Url of the media.
	/// This is a bindable property.
	/// </summary>
	[TypeConverter(typeof(MediaSourceConverter))]
	public MetadataArtworkSource? MetadataArtworkSource
	{
		get => (MediaSource)GetValue(MetadataArtworkUrlProperty);
		set => SetValue(MetadataArtworkUrlProperty, value);
	}

Usage Syntax

XAML:

 <toolkit:MediaElement
     x:Name="MediaElement"
     ShouldAutoPlay="True"
     Source="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
     MetadataArtworkSource="ebedded://robot.jpg"
     MetadataTitle="Big Buck Bunny"
     MetadataArtist="Blender Foundation"/>

Code Behind:

MediaElement.MetadataArtworkSource = MediaSource.FromResource("robot.jpg");  

Drawbacks

None. No reason not to add this.

Alternatives

Adding it with OnPropertyChanged and OnPropertyChanging so that it can dynamically update when added/changed/removed.
This would add significant complexity but could be done. I would suggest adding it in a different PR to keep the complexity down.

Unresolved Questions

No response

Metadata

Metadata

Assignees

Labels

approvedThis Proposal has been approved and is ready to be added to the ToolkitchampionA member of the .NET MAUI Toolkit core team has chosen to champion this featureproposalA fully fleshed out proposal describing a new feature in syntactic and semantic detail

Type

No type

Projects

Status

Proposal Approved

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions