CommunityToolkit / CommunityToolkit/Maui

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

Open
#2,151 6 comments 4 reactions 1 assignee Claimed by @ne0rrmatrix View on GitHub
approved champion proposal
Dominant language
C#
Stars
2.7k
Forks
500
Avg merge
2d 14h
Merged PRs (30d)
7

Description

### Feature name

Add support for local files and package resources to MediaElement

### Link to discussion

https://github.com/CommunityToolkit/Maui/discussions/1989

### Progress tracker

- [X] Android Implementation
- [X] iOS Implementation
- [X] MacCatalyst Implementation
- [X] Windows Implementation
- [ ] Tizen Implementation
- [ ] Unit Tests
- [X] 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:
```csharp
///
/// Backing store for the property.
///
public static readonly BindableProperty MetadataArtworkUrlProperty = BindableProperty.Create(nameof(MetadataArtworkSource), typeof(MediaSource), typeof(MediaElement));
```

```csharp
/// Gets or sets the Artwork Image Url of the media.
/// This is a bindable property.
///
[TypeConverter(typeof(MediaSourceConverter))]
public MetadataArtworkSource? MetadataArtworkSource
{
get => (MediaSource)GetValue(MetadataArtworkUrlProperty);
set => SetValue(MetadataArtworkUrlProperty, value);
}
```

### Usage Syntax

### XAML:
```XAML

```

### 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.