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

Add subtitle support #1918

Draft
wants to merge 139 commits into
base: main
Choose a base branch
from

Conversation

ne0rrmatrix
Copy link
Contributor

@ne0rrmatrix ne0rrmatrix commented Jun 7, 2024

  • Feature/Proposal

Add Support for Subtitles to Media Element.

Description of Change

Adds subtitle support to Windows, Android, iOS, and Mac Catalyst.

Linked Issues

PR Checklist

Additional information

Input on API, naming, and design is appreciated. Nothing is final yet. There were a few people that had ideas from the June meeting. If the people who were at the meeting or are just seeing this now can elaborate on their ideas I will look at them and talk with the other team members about them. I am looking for design, API, and input on naming so we can move this further.

Current Status

  • API is working!
  • All devices support the API.

API:

/// <summary>
/// Backing store for the <see cref="CustomSubtitleParser"/> property.
/// </summary>
public static readonly BindableProperty ParserProperty = 
	BindableProperty.Create(nameof(CustomSubtitleParser), typeof(IParser), typeof(MediaElement), null);

/// <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);

UPDATED VIDEO'S Below!!!

Video:

Windows

2024-07-26.15-40-13.mp4

Android

2024-07-26.15-41-25.mp4

iOS

2024-07-26.16-13-49.mp4

…rt for video players across different platforms (Android, iOS/macOS, and Windows) within the CommunityToolkit.Maui.Extensions namespace. This includes the ability to load subtitles from a URL, parse SRT and VTT subtitle formats, and display the subtitles synchronized with video playback. Key implementations include the `SubtitleExtensions` class for platform-specific handling, `SrtParser` and `VttParser` classes for parsing subtitle files, and the integration of subtitle functionality into the `MediaManager` classes for each platform. Additionally, UI enhancements allow users to select subtitles, and platform-specific adjustments ensure correct subtitle display in various modes.

List of changes:

1. **Cross-Platform Subtitle Support**: Added functionality to display subtitles in the `MediaElement` control, supporting SRT and VTT formats across Android, iOS/macOS, and Windows.
2. **Subtitle File Loading**: Introduced a `SubtitleUrl` property in the `MediaElement` control for specifying the subtitle file URL.
3. **Platform-Specific `SubtitleExtensions`**: Implemented on Android, iOS/macOS, and Windows to handle subtitle loading, parsing, and displaying, with adjustments for fullscreen changes.
4. **Subtitle Parsing Classes**: Added `SrtParser` and `VttParser` static classes for parsing SRT and VTT files into `SubtitleCue` objects.
5. **`SubtitleCue` Class**: Created to represent individual subtitle cues with start/end times and text.
6. **MediaManager Integration**: Modified to incorporate subtitle functionality, including subtitle display based on video playback state and volume changes.
7. **UI Enhancements**: Updated the user interface to allow subtitle selection and ensure subtitles are relevant to the video being played.
8. **Platform-Specific Adjustments**: Implemented adjustments for correct subtitle display in fullscreen mode and during layout changes.
9. **Error Handling and Logging**: Included basic error handling and logging, particularly for subtitle loading methods.
10. **Memory Management**: For Windows, ensured proper disposal of unmanaged resources in the `SubtitleExtensions` class.

These changes significantly enhance the video playback experience by providing users with the ability to display subtitles, thereby making content more accessible and enjoyable across different platforms and devices.
…nctionality within a MAUI application, specifically targeting Windows platforms. The modifications aim to improve the integration of subtitles with the MAUI media element, manage subtitle display based on the video player's full-screen status, and ensure that subtitles are correctly managed and displayed in relation to the media player's state. Here's a summary of the most significant changes:

1. **Integration with MAUI Media Element**: The `SubtitleExtensions` class has been updated to support a new `MauiMediaElement` property. This change involves replacing a `Label` text block with a `Microsoft.UI.Xaml.Controls.TextBlock` for displaying subtitles, facilitating better integration with MAUI's media element on Windows platforms.

2. **Full-Screen State Management**: A new boolean property `isFullScreen` has been introduced to manage the subtitle display based on the video player's full-screen status, enhancing the user experience during full-screen playback.

3. **Enhanced Subtitle Loading**: The `LoadSubtitles` method now requires an additional parameter of type `Microsoft.UI.Xaml.Controls.MediaPlayerElement`, linking the subtitle functionality directly with the media player element. This adjustment increases the flexibility and usability of the subtitle system.

4. **Improved Subtitle Display Logic**: Adjustments have been made to various methods (`MauiMediaElement_WindowsChanged`, `StartSubtitleDisplay`, `Timer_Elapsed`, and `StopSubtitleDisplay`) to accommodate the changes in subtitle management. These modifications ensure that subtitles are correctly added to or removed from the media element's visual tree based on the player's state.

5. **Diagnostic Trace Statements**: The `Timer_Elapsed` and `StopSubtitleDisplay` methods now include diagnostic trace statements to aid in debugging and monitoring subtitle display functionality. These statements log the displayed subtitle cue text and confirm the removal of the subtitle text block from the media element, respectively.

6. **Error Handling and Diagnostics in `MediaManager.windows.cs`**: The `LoadSubtitles` method has been updated to require the `Player` object as a parameter for the `subtitleExtensions.LoadSubtitles` call, ensuring correct association with the media player element. Additionally, a diagnostic trace error statement has been added to log situations where the subtitle extensions, subtitle URL, or player object are not correctly initialized.

List of Changes:
- Updated `SubtitleExtensions` class for better integration with MAUI's media element. [Integration with MAUI Media Element]
- Added `isFullScreen` property for full-screen state management. [Full-Screen State Management]
- Modified `LoadSubtitles` method to enhance subtitle loading. [Enhanced Subtitle Loading]
- Adjusted subtitle display logic in multiple methods. [Improved Subtitle Display Logic]
- Included diagnostic trace statements in `Timer_Elapsed` and `StopSubtitleDisplay` methods. [Diagnostic Trace Statements]
- Improved error handling and diagnostics in `MediaManager.windows.cs`. [Error Handling and Diagnostics in `MediaManager.windows.cs`]
…maintainability, and robustness. Here's a summary of the most important changes:

1. **Simplified Object Initialization**: The initialization of `HttpClient` has been simplified using the target-typed `new` expression, making the code more concise.
2. **Refactoring Conditional Logic**: The handling of the `isFullScreen` state has been refactored from an if-else statement to a switch statement, utilizing pattern matching for better readability.
3. **Improving Null Checks**: An additional null check for `xamlTextBlock` in the `Timer_Elapsed` method has been added to prevent potential null reference exceptions.
4. **Streamlining Visibility Handling**: Redundant null checks for `xamlTextBlock` have been removed, as an earlier check already ensures its non-nullity, thus cleaning up the code.
5. **Removing Redundant Logging**: A redundant logging statement in the `StopSubtitleDisplay` method has been removed, likely to clean up the logging output.

Details of the changes:

- **Simplified Object Initialization**: Changed `httpClient = new HttpClient();` to `httpClient = new();` for cleaner code.
- **Refactoring Conditional Logic**: Refactored `if (!isFullScreen)` to `switch(isFullScreen)` and replaced the else block with `case false:`, improving code maintainability.
- **Improving Null Checks**: Added a null check `if (mediaElement?.Position is null || cues.Count == 0 || string.IsNullOrEmpty(mediaElement.SubtitleUrl) || xamlTextBlock is null)` to enhance code robustness.
- **Streamlining Visibility Handling**: Removed unnecessary null checks `if (xamlTextBlock is not null)` after ensuring `xamlTextBlock` is not null earlier in the code.
- **Removing Redundant Logging**: Removed the logging statement `System.Diagnostics.Trace.TraceInformation("Removed text block from player parent");` to clean up logging output.
… functionality. Specifically, the application will no longer log information related to cue text to trace listeners following the elapse of a timer and the presence of a cue. This modification could impact how developers or users monitor and debug the application, as they will no longer receive automatic trace information about cue text events.

### Summary of Change:
- **Removal of Cue Text Logging**: The specific line of code responsible for logging cue text information using `System.Diagnostics.Trace.TraceInformation` has been removed. This action disables the application's ability to output cue text information to trace listeners upon the occurrence of a cue event post-timer elapse.

_Reference to Code Change: Removal of `System.Diagnostics.Trace.TraceInformation` for cue text logging._
…SubtitleExtensions` class immutable by converting it from a nullable, modifiable field to a read-only nullable field. This ensures that once `xamlTextBlock` is assigned, it cannot be modified. To accommodate this change, the constructor of the `SubtitleExtensions` class has been updated to initialize `xamlTextBlock` with a new `TextBlock` instance, setting up default properties for this instance. Consequently, the conditional initialization of `xamlTextBlock` within the `LoadSubtitles` method has been removed, as it is no longer necessary or possible due to the field's read-only status.

List of changes:
1. The `xamlTextBlock` field in the `SubtitleExtensions` class has been changed to a read-only nullable field to enforce immutability after its initial assignment. This modification ensures that the `xamlTextBlock` cannot be altered once it is set, enhancing the stability and predictability of how `xamlTextBlock` is used within the class.
2. In the `SubtitleExtensions` constructor, `xamlTextBlock` is now initialized with a new `TextBlock` instance. This instance is configured with default settings, including empty text, a specific margin, visibility, alignment, foreground color, font size, and text wrapping settings. This change ensures that `xamlTextBlock` is always in a ready-to-use state immediately after an instance of `SubtitleExtensions` is created.
3. The removal of conditional initialization of `xamlTextBlock` within the `LoadSubtitles` method. Since `xamlTextBlock` is initialized in the constructor and is read-only, there's no need or ability to reinitialize or modify it in the `LoadSubtitles` method, simplifying the method's logic and ensuring consistency in how `xamlTextBlock` is used.
…ity within a media playback context, introducing more robust and flexible handling of subtitles, improving thread safety, and ensuring UI updates are performed correctly. The most significant changes include the modification of the `SubtitleExtensions` constructor and methods, refactoring of the `LoadSubtitles` method, adjustments to subtitle display lifecycle methods (`StartSubtitleDisplay`, `StopSubtitleDisplay`, and `UpdateSubtitle`), and improvements to the `MediaManager` class for better immutability and thread safety.

### Important Changes Summary:

1. **Namespace and Class Imports:** Introduction of new imports to support enhanced subtitle functionality.
2. **SubtitleExtensions Constructor Modification:** Changes to how and when the subtitle label is initialized and added to the view, aiming for better flexibility and control.
3. **LoadSubtitles Method Refactoring:** Simplification and enhancement of subtitle content loading, including support for nullability and a more concise approach to parsing based on file extension.
4. **StartSubtitleDisplay Method Changes:** Ensures UI updates are performed on the main thread and updates subtitle label positioning logic to be more dynamic and responsive during playback.
5. **StopSubtitleDisplay and UpdateSubtitle Method Adjustments:** Adjustments to maintain the subtitle label in the view hierarchy, potentially for performance or state management reasons.
6. **CalculateSubtitleFrame Method Signature Change:** Decouples the frame calculation method from instance state, allowing for more flexible usage.
7. **MediaManager Class Adjustments:** Enforces immutability of the `CancellationTokenSource` to ensure predictable behavior and thread safety.

### Detailed Changes:

- **Namespace and Class Imports:** Added to support new functionality in `SubtitleExtensions`. [Namespace and Class Imports]
- **SubtitleExtensions Constructor Modification:** Improved subtitle frame calculation and modified when the subtitle label is added to the view. [SubtitleExtensions Constructor Modification]
- **LoadSubtitles Method Refactoring:** Enhanced loading logic with nullability support and a more streamlined approach to parsing subtitle formats. [LoadSubtitles Method Refactoring]
- **StartSubtitleDisplay Method Changes:** Added main thread requirement for UI updates and refined frame calculation during playback. [StartSubtitleDisplay Method Changes]
- **StopSubtitleDisplay and UpdateSubtitle Method Adjustments:** Removed unnecessary removal of the subtitle label from the view hierarchy in `UpdateSubtitle`. [StopSubtitleDisplay and UpdateSubtitle Method Adjustments]
- **CalculateSubtitleFrame Method Signature Change:** Made the method static and changed its signature for broader applicability. [CalculateSubtitleFrame Method Signature Change]
- **MediaManager Class Adjustments:** Changed `subTitles` field to be read-only for better immutability and thread safety. [MediaManager Class Adjustments]
…urrentCue` variable in a C# codebase. This modification enhances readability and aligns with modern C# coding practices by replacing the traditional inequality operator (`!=`) with the more contemporary `is not` pattern for null checks.

### Change Summary:
- Updated the null check for `currentCue` from using `!=` to `is not` to improve code readability and adhere to modern C# standards.

Reference to the code change:
- The code change modifies the null check of `currentCue` from using `!=` to using the `is not` pattern, transitioning to a more modern and readable syntax for checking non-null values in C#.
… label as a subview to the playerViewController's view within a method responsible for starting subtitle display. This modification suggests a change in how subtitles are managed or displayed in the application, potentially impacting the user interface or the way subtitles are rendered during video playback.

### Summary of Change:
- **Removal of Subtitle Label Addition**: The specific line of code that added the subtitle label to the playerViewController's view has been removed from the `StartSubtitleDisplay` method. This indicates a significant change in the approach to displaying subtitles, possibly due to a redesign of the subtitle rendering system or an optimization of the existing process.

### Detailed Change:
- In the file `SubtitleExtensions.macios.cs`, within the method `StartSubtitleDisplay`, the line `playerViewController.View?.AddSubview(subtitleLabel);` was removed. This action signifies that the subtitle label is no longer directly added to the playerViewController's view as part of initiating subtitle display. This could reflect a shift towards a different method of subtitle integration or an update to the user interface design that necessitates this change.
…of a text block element (`xamlTextBlock`) based on a condition. This condition checks the state of a variable named `isFullScreen`. If `isFullScreen` is true, indicating that a full-screen mode is active, the font size of the text block is increased to 24. Conversely, if `isFullScreen` is false, suggesting that the full-screen mode is not active, the font size is set to a smaller size of 16. This modification ensures that the text size is dynamically adjusted to enhance readability and user experience depending on the display mode.

### List of Changes:
- Conditional setting of `xamlTextBlock` font size based on the `isFullScreen` variable. The font size is set to 24 when `isFullScreen` is true and 16 when it is false.
…the `CommunityToolkit.Maui.Extensions` namespace primarily focus on refactoring and enhancing the subtitle display capabilities for a video player. These changes aim to improve clarity, maintainability, and performance. The most significant updates include the reorganization of field declarations and initializations, enhancements to the constructor for better subtitle styling, adjustments for full-screen layout changes, and optimizations in the subtitle display start and stop methods. Additionally, general code cleanup has been performed to remove unnecessary code and simplify logic.

### Important Changes:

1. **Initialization and Declaration Changes:**
   - Fields such as `httpClient`, `textBlock`, `timer`, `cues`, and `mediaElement` have been reorganized for better clarity and maintainability.
   - `textBlock` is now initialized within the constructor with predefined properties like background color, padding, text color, and visibility.

2. **Constructor Enhancements:**
   - The constructor now includes detailed initialization of `textBlock`, setting up text size, alignment, scroll bar settings, and visibility state to ensure it's ready for displaying subtitles with the desired styling.

3. **FullScreen Layout Adjustments:**
   - Code has been simplified for handling full-screen layout changes, focusing on efficiently adding and removing subtitle display views and adjusting layout parameters for correct positioning.

4. **Subtitle Display Start and Stop Methods:**
   - `StartSubtitleDisplay` method streamlined by removing redundant `textBlock` initialization and adding a null check.
   - `StopSubtitleDisplay` method now clears the displayed subtitles by setting `textBlock` text to an empty string.

5. **General Code Cleanup:**
   - Unnecessary dispatcher invocations removed, conditional checks simplified, and redundant code blocks eliminated, enhancing readability and performance.

These changes collectively contribute to a more efficient, maintainable, and user-friendly subtitle display functionality within the video player component.
…e customization features across various platforms (Android, iOS/macOS, and Windows) for media playback. These changes allow users to customize the font and font size of subtitles, enhancing the accessibility and user experience of media elements. The changes include the addition of `SubtitleFont` and `SubtitleFontSize` properties to the `IMediaElement` interface and `MediaElement` class, adjustments in subtitle display logic on different platforms to utilize these new properties, and general code cleanup and refactoring to support these enhancements.

### List of Changes:

1. **MediaElement Subtitle Customization**
   - Introduced `SubtitleFont` and `SubtitleFontSize` properties to `IMediaElement` and `MediaElement` for subtitle font and size customization.

2. **Android Subtitle Display Adjustments**
   - Updated subtitle display logic in `SubtitleExtensions.android.cs` to use the new customization properties, ensuring subtitles are displayed with the specified font and size on Android devices.

3. **iOS/macOS Subtitle Display Adjustments**
   - Added logic in `SubtitleExtensions.macios.cs` to apply `SubtitleFont` and `SubtitleFontSize` for subtitle display, enabling custom font and size on iOS and macOS.

4. **Windows Subtitle Display Adjustments**
   - Adjusted subtitle display in `SubtitleExtensions.windows.cs` to utilize the new properties for subtitle customization on Windows platforms.

5. **General Code Cleanup and Refactoring**
   - Removed unused `using` directives in `SubtitleExtensions.macios.cs` and made code adjustments for consistency with the new subtitle customization features.

6. **Subtitle Loading and Display Enhancements**
   - Enhanced subtitle loading and display across Android, iOS/macOS, and Windows to support the new customization options, ensuring correct display according to specified settings.

7. **API and Property Changes**
   - Added new properties (`SubtitleFont`, `SubtitleFontSize`) for subtitle customization in the `IMediaElement` interface and `MediaElement` class, and adjusted existing methods and properties to integrate these features seamlessly with existing media playback functionality.
…ality and handling window state changes more dynamically across different platforms, particularly focusing on iOS and MacCatalyst. These changes include adjustments to subtitle font settings based on the operating system, improvements in subtitle display and positioning, and better handling of window state changes such as entering or exiting full screen.

### Summary of Key Changes:

1. **Subtitle Font Setting Logic Enhancement**: The logic for setting subtitle fonts has been adjusted to cater to different platforms, setting "Avenir-Book" for iOS and MacCatalyst, and "monospace" for others within the `ChangeSourceClicked` method in `MediaElementPage.xaml.cs`.

2. **Dynamic Subtitle Display Handling**: The `SubtitleExtensions` class has been modified to handle nullable UILabels for subtitles and introduced dynamic management of subtitle display and font settings through a nullable `UIViewController` and `UIFont`.

3. **Window State Change Event Handling**: A new event, `WindowsChanged`, has been introduced and is subscribed to in the `SubtitleExtensions` class to adjust subtitle properties and positioning dynamically based on window state changes.

4. **Enhanced Subtitle Functionality**: Methods within `SubtitleExtensions` such as `LoadSubtitles`, `StartSubtitleDisplay`, `StopSubtitleDisplay`, and `UpdateSubtitle` have been updated or modified to improve subtitle loading, display, positioning, and updating during playback.

5. **Full-Screen Presentation Event Handling**: In `MediaManager.macios.cs`, a delegate for the `AVPlayerViewController` has been set to handle full-screen presentation events, and a new class `MediaManagerDelegate` has been introduced to manage these events, allowing for a more responsive UI during window state changes.

### Detailed Changes:

- **MediaElementPage.xaml.cs Modifications**: Adjusted subtitle font setting logic for different platforms within the `ChangeSourceClicked` method.
- **SubtitleExtensions.macios.cs Additions and Modifications**: Enhanced functionality with additional `using` directives, modified the `SubtitleExtensions` class for dynamic subtitle management, and introduced handling for the `WindowsChanged` event.
- **MediaManager.macios.cs Modifications**: Updated to set a delegate for handling full-screen presentation events and introduced `MediaManagerDelegate` for managing window state changes.

These changes collectively aim to improve the user experience by ensuring subtitles are displayed correctly and responsively across different platforms and during various window state changes, such as entering or exiting full screen.
…mechanism in an Android context, enhancing maintainability, readability, and potentially performance. Key adjustments include the removal of the `WidthRequest` property from `MediaElementPage.xaml` to streamline responsive design, the addition of a dependency comment in `SubtitleExtensions.android.cs`, and significant refactoring within the `SubtitleExtensions` class to simplify layout management and subtitle display methods.

### Most Important Changes:
1. **Simplification of Responsive Design in MediaElementPage.xaml**: The removal of the `WidthRequest` property for different idioms indicates a move towards a simpler or refactored responsive design approach.
2. **Dependency Annotation in SubtitleExtensions.android.cs**: A comment was added to highlight a dependency on a specific pull request, suggesting that the changes are contingent on the acceptance of related modifications.
3. **Refactoring of SubtitleExtensions Class**: This includes reorganization and simplification of class fields, introduction of a new `textBlockLayout` for flexible subtitle display, and significant method adjustments to streamline fullscreen toggling and subtitle display management.

### Detailed List of Changes:
- **MediaElementPage.xaml Adjustments**: Removal of `WidthRequest` property for `MediaElement` to simplify responsive design. [MediaElementPage.xaml]
- **SubtitleExtensions.android.cs Namespace and Using Directives**: Added a dependency comment and adjusted namespace usage for better readability. [SubtitleExtensions.android.cs]
- **SubtitleExtensions Class Field Modifications**: Reorganized fields, introduced `textBlockLayout`, and removed complex layout fields like `relativeLayout` and `fullScreenLayout` to simplify layout management. [SubtitleExtensions]
- **Constructor and Method Adjustments in SubtitleExtensions**: Added initialization for `textBlockLayout`, refactored `MauiMediaElement_WindowsChanged` method for better readability, and simplified `StartSubtitleDisplay` and `StopSubtitleDisplay` methods by directly managing the `textBlock`. [SubtitleExtensions]

These changes collectively aim to enhance the subtitle functionality within an Android application by making the codebase more manageable and the user interface more efficient.
- Removed outdated conditional comment related to PR# 1873.
- Enhanced namespace access with additional `using` directives for Android and CommunityToolkit.
- Modified `textBlock` to be nullable, supporting dynamic UI updates.
- Centralized `textBlock` initialization in the constructor via `InitializeTextBlock()`.
- Introduced `VerifyAndRetrieveCurrentWindowResources` for resource validation.
- Updated `MauiMediaElement_WindowsChanged` for null checks and re-initialization of `textBlock`.
- Added dynamic re-initialization of `textBlock` in `InitializeTextBlock()`, adjusting properties like text alignment and color.
- Improved safety in `StopSubtitleDisplay` with null checks for `textBlock`.
- Made Windows platform-specific UI adjustments, including increased `xamlTextBlock` bottom margin for better visual separation.
Refactored and simplified the SubtitleExtensions class by removing Android-specific dependencies and changing its base class to IDisposable for better resource management. Introduced a destructor and an explicit Dispose method to enhance cleanup of unmanaged resources. Added and improved methods for subtitle display management, including a new StopSubtitleDisplay method and reorganization of textBlock initialization. Restored functionality for dynamic UI adjustments with the reintroduction of VerifyAndRetrieveCurrentWindowResources method and event handler. Updated fullscreen handling logic for better subtitle visibility control. General code cleanup was performed, including the removal of unused imports, unnecessary null checks, and making the Dispose method virtual for extensibility. Adjusted instantiation in MediaManager.android.cs to align with constructor changes.
This commit introduces several key improvements and cleanups across the codebase, focusing on enhancing media playback and subtitle management. Notably, we've added initialization for empty subtitle URLs in `MediaElementPage.xaml.cs` to prevent issues when changing media sources. Both `SrtParser.cs` and `VttParser.cs` have been updated to return an empty list of cues for null or empty subtitle content, optimizing parsing efficiency and reliability.

We've removed unused namespaces, such as `System.Data;` in `SubtitleExtensions.android.cs`, and refactored `SubtitleExtensions` classes across platforms to include better error handling, clearer event management, and more robust null checking using `ArgumentNullException.ThrowIfNull`. These changes ensure a cleaner, more maintainable codebase with improved readability and compile-time efficiency.

Additionally, we've made significant enhancements in media manager classes by ensuring proper subtitle and session management, including stopping and clearing subtitles appropriately and following proper disposal patterns to prevent memory leaks.

Minor code improvements were also made to enhance readability, efficiency, and robustness, including the removal of redundant null checks, the use of pattern matching, and the simplification of switch statements. Lastly, we've adjusted the raising of `WindowsChanged` events to ensure consistent behavior across different media playback scenarios.

These collective efforts aim to bolster the codebase's maintainability, efficiency, and reliability, especially in handling media playback and subtitles across various platforms.
Enhanced the `MauiMediaElement_WindowsChanged` method in `SubtitleExtensions.windows.cs` to adjust subtitle text size based on the full-screen state of the media element. Specifically, when in full-screen mode, the subtitle font size is now increased by 8.0 units over the base `mediaElement.SubtitleFontSize`. Conversely, when not in full-screen mode, the subtitle font size reverts to the base size. Additionally, simplified the `Timer_Elapsed` method by removing redundant code for setting `xamlTextBlock` font properties, streamlining the subtitle display logic.
2. fix windows font size when loading
3. fix windows font size when changing from normal to full screen and back.
@ne0rrmatrix ne0rrmatrix added the 📽️ MediaElement Issue/PR that has to do with MediaElement label Aug 4, 2024
@brminnick brminnick removed the needs discussion Discuss it on the next Monthly standup label Sep 5, 2024
@ne0rrmatrix
Copy link
Contributor Author

I have rewritten this and will be updating it after update to media 3.

@MuhammadTalhaahmed
Copy link

I have rewritten this and will be updating it after update to media 3.
Did you have done everything in MAUI Subtitles for media element , when will Media Element is going to have these updates ?

@ne0rrmatrix
Copy link
Contributor Author

I have rewritten this and will be updating it after update to media 3.
Did you have done everything in MAUI Subtitles for media element , when will Media Element is going to have these updates ?

I am waiting on this PR: #2076 After it merges I will update this PR with updated version that has full native support that does the same thing as the above example. It just has no custom libraries and is better integrated with each platform. IE, the new version has button support and contextual menus for windows and android. For ios the only limitation is you can only set one subtitle and no built in menu support. The native support for subtitles in IOS is tied to using an HLS stream which requires nothing on our end for it to work. That functionality currently is fully working and supported as is.

@ne0rrmatrix ne0rrmatrix added the needs discussion Discuss it on the next Monthly standup label Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📽️ MediaElement Issue/PR that has to do with MediaElement needs discussion Discuss it on the next Monthly standup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Proposal] Add Subtitle Support to Media Element
4 participants