-
Notifications
You must be signed in to change notification settings - Fork 124
Update MediaElement documentation to include foreground service #613
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
Open
ne0rrmatrix
wants to merge
13
commits into
MicrosoftDocs:main
Choose a base branch
from
ne0rrmatrix:AndroidForegroundService
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
5b9f275
Update MediaElement documentation to include foreground service requi…
ne0rrmatrix b6a9ff7
Fix minor error
ne0rrmatrix 4401ea3
Update MediaElement documentation to include background playback perm…
ne0rrmatrix 7aaf986
Clarify documentation for enabling background video playback in Media…
ne0rrmatrix 781942a
Add documentation for enabling foreground service in MediaElement on …
ne0rrmatrix 1c4b6d0
Update MediaElement documentation to clarify metadata setup for rich …
ne0rrmatrix 1384646
Clarify instructions for enabling rich media notifications in MediaEl…
ne0rrmatrix b42d6e1
Update docs/maui/views/MediaElement.md
ne0rrmatrix 0893474
Update docs/maui/views/MediaElement.md
ne0rrmatrix eb42327
Update docs/maui/views/MediaElement.md
ne0rrmatrix 420add9
Update docs/maui/views/MediaElement.md
ne0rrmatrix b099bb4
Update docs/maui/get-started.md
ne0rrmatrix 7aeed1b
Fix duplication
ne0rrmatrix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,13 +49,13 @@ First the using statement needs to be added to the top of your *MauiProgram.cs* | |
| using CommunityToolkit.Maui.MediaElement; | ||
| ``` | ||
|
|
||
| In order to use the `MediaElement` correctly the `UseMauiCommunityToolkitMediaElement` method must be called on the `MauiAppBuilder` class when bootstrapping an application the *MauiProgram.cs* file. The following example shows how to perform this. | ||
| In order to use the `MediaElement` correctly the `UseMauiCommunityToolkitMediaElement` method must be called on the `MauiAppBuilder` class when bootstrapping an application the *MauiProgram.cs* file. The following example shows how to perform this. If you fail to set `enableForeGroundService` to `true` on Android, background playback will not work. If you do not need background playback, you can set this to `false`. If you fail to call this method, an exception will be thrown when trying to use the `MediaElement`. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should call out the added text here to make it more obvious. Can we move it out of the paragraph and add to an important banner? I think it's added like > [!IMPORTANT] |
||
|
|
||
| ```csharp | ||
| var builder = MauiApp.CreateBuilder(); | ||
| builder | ||
| .UseMauiApp<App>() | ||
| .UseMauiCommunityToolkitMediaElement() | ||
| .UseMauiCommunityToolkitMediaElement(enableForegroundService: true); // Set to `false` if Rich Notifications and background playback is not required | ||
| ``` | ||
|
|
||
| For more information on how to do this, please refer to the [Get Started](../get-started.md?tabs=CommunityToolkitMauiMediaElement#adding-the-nuget-packages) page. | ||
|
|
@@ -80,6 +80,7 @@ public class MainActivity : MauiAppCompatActivity | |
|
|
||
| For a full example of this method included in an application please refer to the [.NET MAUI Community Toolkit Sample Application](https://github.com/CommunityToolkit/Maui/blob/main/samples/CommunityToolkit.Maui.Sample/Platforms/Android/MainActivity.cs) | ||
|
|
||
| #### 2. Add required permissions to `AndroidManifest.xml` | ||
| ### [Mac Catalyst](#tab/mac) | ||
|
|
||
| Edit the `Info.plist` for `MacCatalyst` and add the following keys. | ||
|
|
@@ -149,6 +150,15 @@ By default, the media that is defined by the `Source` property doesn't immediate | |
|
|
||
| Platform provided media playback controls are enabled by default, and can be disabled by setting the `ShouldShowPlaybackControls` property to `false`. | ||
|
|
||
| ### Use Rich Media Notifications | ||
| A `MediaElement` can show rich media notifications on Android, iOS, Mac Catalyst, and Windows when media is playing in the background. To enable rich media notifications, the following steps are required: | ||
| 1. Enable background video playback by setting the `enableForegroundService` parameter to `true` when calling the `UseMauiCommunityToolkitMediaElement` method in *MauiProgram.cs*. Refer to the **Initializing the package** section above for more information. | ||
| 2. Platform specific setup as described in the [Platform specific initialization](#platform-specific-initialization) section. | ||
| 3. Set the `MetadataTitle`, `MetadataArtist`, and `MetadataArtworkUrl` properties to provide metadata for the media that is playing as described in the [Using Metadata](#using-metadata) section. | ||
|
|
||
| ### Foreground service on Android | ||
| To enable background playback on Android, you must set the `enableForegroundService` parameter to `true` when calling the `UseMauiCommunityToolkitMediaElement` method in *MauiProgram.cs*. If you fail to do this, an exception will be thrown when the application is run on Android. | ||
|
|
||
| ### Using Metadata | ||
|
|
||
| A `MediaElement` can use metadata for `MediaElement.MetadataTitle`, `MediaElement.MetadataArtist` and `MediaElement.MetadataArtworkUrl`. You can set | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.