Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] Add Subtitle Support to Media Element #1899

Open
5 of 8 tasks
ne0rrmatrix opened this issue May 24, 2024 · 2 comments · May be fixed by #1918
Open
5 of 8 tasks

[Proposal] Add Subtitle Support to Media Element #1899

ne0rrmatrix opened this issue May 24, 2024 · 2 comments · May be fixed by #1918
Assignees
Labels
approved This Proposal has been approved and is ready to be added to the Toolkit champion A member of the .NET MAUI Toolkit core team has chosen to champion this feature 📽️ MediaElement Issue/PR that has to do with MediaElement proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail

Comments

@ne0rrmatrix
Copy link
Contributor

ne0rrmatrix commented May 24, 2024

Feature name

Media Element Subtitles

Link to discussion

#1867

Progress tracker

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

Summary

Add support for Subtitles to Media Element. Initial support for Windows, Mac, iOS, and Android. Subtitle format allowed at launch include srt and sub.

Windows

windows-subtitle-normal

Windows-subtitle-fullscreen

Android

Android-normal-subtitles

Android-subtitles-fullscreen

IOS

2024-05-09.17-11-43.mp4

Motivation

I would like to help support people who have difficulty with hearing or need assistance in loud noisy environments where it is hard to hear the dialogue. Or people that want translations of foreign languages spoken that they do not know. Other people just like subtitles. This will add robust support that can be expanded later.

Detailed Design

API:

	/// <summary>
	/// Backing store for the <see cref="SubtitleFont"/> property.
	/// </summary>
	public static readonly BindableProperty SubtitleFontProperty = BindableProperty.Create(nameof(SubtitleFont), typeof(string), typeof(MediaElement), string.Empty);
	
	/// <summary>
	/// Backing store for the <see cref="SubtitleFontSize"/> property.
	/// </summary>
	public static readonly BindableProperty SubtitleFontSizeProperty = BindableProperty.Create(nameof(SubtitleFontSize), typeof(double), typeof(MediaElement), 16.0);

	/// <summary>
	/// Backing store for the <see cref="SubtitleUrl"/> property.
	/// </summary>
	public static readonly BindableProperty SubtitleProperty = BindableProperty.Create(nameof(SubtitleUrl), typeof(string), typeof(MediaElement), string.Empty);

Usage Syntax

XAML Usage:

 <toolkit:MediaElement
     x:Name="MediaElement"
     ShouldAutoPlay="True"
     SubtitleFont="monospace"
     SubtitleFontSize="20"
     SubtitleUrl="https://raw.githubusercontent.com/ne0rrmatrix/SampleVideo/main/SRT/WindowsVideo.srt"
     Source="https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"/>

C# Code behind example

MediaElement.SubtitleFont = "monospace";
MediaElement.SubtitleFontSize = 16;
MediaElement.SubtitleUrl = "https://raw.githubusercontent.com/ne0rrmatrix/SampleVideo/main/SRT/WindowsVideo.srt";
MediaElement.Source = MediaSource.FromResource("WindowsVideo.mp4");

Drawbacks

Currently it uses a custom class to read the subtitle files and convert them to strings that can be used at specific times in a text box appropriate for each OS. This is a new class that only supports plain text at the moment. Non standard files and RTF formatted files are not supported.

Alternatives

The custom class for reading subtitle files was written to allow iOS and Mac Catalyst support as the current methods are to use m3u8 files and do not support directly linking a subtitle file. ATM we have support for m3u8 files but we have no control over how or what is displayed at all. Android and Windows both have robust libraries that support subtitles. They do not support any common format of subtitles.

ATM if you want uniform support for multiple different formats on each and every device my custom class is the way to go.

Unresolved Questions

How are we going to use/add fonts? Are we going to go the normal route and just add fonts to the project and import them like any other maui project? Are we going to just use built in supported OS fonts for each device?

@ne0rrmatrix ne0rrmatrix added new proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail labels May 24, 2024
@brminnick brminnick added the needs discussion Discuss it on the next Monthly standup label May 24, 2024
@vhugogarcia vhugogarcia added the 📽️ MediaElement Issue/PR that has to do with MediaElement label May 27, 2024
@brminnick brminnick added champion A member of the .NET MAUI Toolkit core team has chosen to champion this feature and removed new needs discussion Discuss it on the next Monthly standup labels Jun 6, 2024
@brminnick brminnick added the approved This Proposal has been approved and is ready to be added to the Toolkit label Jun 6, 2024
@ne0rrmatrix ne0rrmatrix linked a pull request Jun 7, 2024 that will close this issue
6 tasks
@ne0rrmatrix
Copy link
Contributor Author

All the work for this features current API is done. I have been refactoring code. I need to update the docs and get them approved. In about another week I will mark it as ready for review. I need to do device testing to see if there are any show stopper bugs or things that emulators missed.

@imememani
Copy link

How's this looking? Feel like this could be a really great addition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved This Proposal has been approved and is ready to be added to the Toolkit champion A member of the .NET MAUI Toolkit core team has chosen to champion this feature 📽️ MediaElement Issue/PR that has to do with MediaElement proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants