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

Update Media Element to use Media3 #2076

Open
wants to merge 92 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 75 commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
ed2aebc
Migrate to AndroidX Media3 library
ne0rrmatrix Jul 31, 2024
712a022
Update AndroidX packages and refactor MediaManager
ne0rrmatrix Jul 31, 2024
d097e97
Refactor MediaManager and update to AndroidX Media3
ne0rrmatrix Aug 1, 2024
524c3e0
Update AndroidX packages and enhance MediaManager
ne0rrmatrix Aug 1, 2024
13e8144
Refactor MediaManager and update package references
ne0rrmatrix Aug 2, 2024
643f7f4
Merge branch 'CommunityToolkit:main' into Media3
ne0rrmatrix Aug 2, 2024
86fbb29
Add TODO and note with request for help solving async issue with seek…
ne0rrmatrix Aug 2, 2024
81bf905
Merge branch 'main' into Media3
ne0rrmatrix Aug 2, 2024
92fdcd9
Simplify player state handling and seeking operations
ne0rrmatrix Aug 4, 2024
02a7520
Merge branch 'main' into Media3
ne0rrmatrix Aug 4, 2024
294f6d2
Update .NET version, playback states, and error handling
ne0rrmatrix Aug 4, 2024
7139e1a
Refactor player control and resource disposal
ne0rrmatrix Aug 4, 2024
9992bcf
Merge branch 'main' into Media3
ne0rrmatrix Aug 8, 2024
5743aff
Merge branch 'main' into Media3
ne0rrmatrix Aug 9, 2024
5b39d8a
Merge branch 'main' into Media3
ne0rrmatrix Aug 9, 2024
c967d6b
Merge branch 'main' into Media3
ne0rrmatrix Aug 9, 2024
56ce4ba
Update changes from media2 for playerView poster to media3 version th…
ne0rrmatrix Aug 9, 2024
e306d86
Merge branch 'CommunityToolkit:main' into Media3
ne0rrmatrix Aug 10, 2024
9d2aca9
Add `SafeFireAndForget`
brminnick Aug 12, 2024
391422e
Merge branch 'main' into Media3
ne0rrmatrix Aug 19, 2024
a9803df
Merge branch 'CommunityToolkit:main' into Media3
ne0rrmatrix Aug 19, 2024
25d1a83
Update nuget version and apply fixes for changes
ne0rrmatrix Aug 20, 2024
c091d74
Merge branch 'Media3' of https://github.com/ne0rrmatrix/MauiOld into …
ne0rrmatrix Aug 20, 2024
3491641
Merge branch 'CommunityToolkit:main' into Media3
ne0rrmatrix Aug 21, 2024
a077367
Merge branch 'CommunityToolkit:main' into Media3
ne0rrmatrix Aug 22, 2024
eb760b9
Merge branch 'CommunityToolkit:main' into Media3
ne0rrmatrix Aug 29, 2024
6f7227f
Merge branch 'main' into Media3
ne0rrmatrix Sep 2, 2024
86d0339
Merge branch 'main' into Media3
ne0rrmatrix Sep 4, 2024
0a833d9
Merge branch 'main' into Media3
brminnick Sep 5, 2024
e966505
Merge branch 'CommunityToolkit:main' into Media3
ne0rrmatrix Sep 9, 2024
8f42eea
Merge branch 'main' into Media3
ne0rrmatrix Sep 10, 2024
e772a54
Update .NET, Maui, and AndroidX versions; refactor MediaManager
ne0rrmatrix Sep 10, 2024
7da3e66
Refactor media controls to use modern Android APIs
ne0rrmatrix Sep 11, 2024
f2d7c66
Merge branch 'Media3' of https://github.com/ne0rrmatrix/MauiOld into …
ne0rrmatrix Sep 11, 2024
2ce91d9
Merge branch 'CommunityToolkit:main' into Media3
ne0rrmatrix Sep 11, 2024
4ce68b2
Merge branch 'CommunityToolkit:main' into Media3
ne0rrmatrix Sep 12, 2024
817f74b
Refactor notification handling with INotificationService
ne0rrmatrix Sep 13, 2024
23d9b1b
Merge branch 'Media3' of https://github.com/ne0rrmatrix/MauiOld into …
ne0rrmatrix Sep 13, 2024
1786dd0
Merge branch 'main' into Media3
ne0rrmatrix Sep 13, 2024
041a06c
- Fix dependancy chain for Media Element after switching from local t…
ne0rrmatrix Sep 13, 2024
34537a0
Remove duplicate `PackageReference`
ne0rrmatrix Sep 13, 2024
8028abe
Update media session to use random id.
ne0rrmatrix Sep 16, 2024
58c5b70
Merge branch 'main' into Media3
ne0rrmatrix Sep 16, 2024
d31e5b9
- Fix buttons receiver log error.
ne0rrmatrix Sep 16, 2024
d27bdb9
removed commented code that is no longer relevent
ne0rrmatrix Sep 16, 2024
3410f00
Remove unused method
ne0rrmatrix Sep 16, 2024
f3b372e
Merge branch 'main' into Media3
ne0rrmatrix Sep 16, 2024
2f51474
Update src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.andr…
ne0rrmatrix Sep 17, 2024
4d97679
Merge branch 'main' into Media3
ne0rrmatrix Sep 17, 2024
419329e
- Remove `INotiifcation` Interface
ne0rrmatrix Sep 17, 2024
f8e82cd
Merge branch 'Media3' of https://github.com/ne0rrmatrix/MauiOld into …
ne0rrmatrix Sep 17, 2024
1ef0f9b
- Fix issue with variable name mismatch
ne0rrmatrix Sep 17, 2024
457d31c
- Update all classes to use a single type of check for API level on A…
ne0rrmatrix Sep 17, 2024
4f4d2ad
- Fix one more API check
ne0rrmatrix Sep 17, 2024
c29f3f5
- Remove suppression no longer required
ne0rrmatrix Sep 17, 2024
c72e80d
Merge branch 'main' into Media3
ne0rrmatrix Sep 17, 2024
f0be701
Add comment about `p0` event args parameter
ne0rrmatrix Sep 17, 2024
2347e4f
Merge branch 'Media3' of https://github.com/ne0rrmatrix/MauiOld into …
ne0rrmatrix Sep 17, 2024
6ead14e
Merge branch 'CommunityToolkit:main' into Media3
ne0rrmatrix Sep 18, 2024
251be66
Refactor MediaManager to use AndroidX libraries
ne0rrmatrix Sep 20, 2024
627c102
Refactor Code
brminnick Sep 20, 2024
853705c
Delete CommunityToolkit.Maui.MediaElement.sln
brminnick Sep 20, 2024
6c7d86b
Improve resource management and notifications
ne0rrmatrix Sep 21, 2024
f1b6e13
Merge branch 'Media3' of https://github.com/ne0rrmatrix/MauiOld into …
ne0rrmatrix Sep 21, 2024
b9699ff
Merge branch 'main' into Media3
ne0rrmatrix Sep 21, 2024
9070895
Refactor media handling and notification updates
ne0rrmatrix Sep 22, 2024
24b2086
Migrate to AndroidX Media3 and enhance media controls
ne0rrmatrix Sep 22, 2024
c7616e0
Remove fonts added for testing
ne0rrmatrix Sep 22, 2024
e858911
Merge branch 'main' into Media3
ne0rrmatrix Sep 22, 2024
b245c92
Refactored media service to inherit player. Behavior previously was M…
ne0rrmatrix Sep 23, 2024
785df3f
Refactor MediaElement and MediaControlsService
ne0rrmatrix Sep 23, 2024
12332c3
remove unused variable. Added null checks.
ne0rrmatrix Sep 23, 2024
c3bbe8e
Enhance null safety and refactor notification updates
ne0rrmatrix Sep 23, 2024
11bd2d4
Refactor notification ID handling in MediaControlsService
ne0rrmatrix Sep 23, 2024
bb55fe8
Merge branch 'main' into Media3
ne0rrmatrix Sep 23, 2024
f97ebd0
Merge branch 'main' into Media3
ne0rrmatrix Sep 24, 2024
76ecf47
Update service behavior. If notifications are disabled do not start s…
ne0rrmatrix Sep 24, 2024
75ffa0d
Merge branch 'Media3' of https://github.com/ne0rrmatrix/MauiOld into …
ne0rrmatrix Sep 24, 2024
3b0eec4
Remove unused using directives in MediaControlsService
ne0rrmatrix Sep 24, 2024
005eb79
Updated to address null intent. Added rebind override to add notifica…
ne0rrmatrix Sep 24, 2024
6b8c952
Update nugets for media 3
ne0rrmatrix Sep 24, 2024
ab9cb9d
Merge branch 'main' into Media3
ne0rrmatrix Sep 27, 2024
1d4dbf0
Merge branch 'main' into Media3
ne0rrmatrix Oct 1, 2024
ad2edac
Merge branch 'main' into Media3
ne0rrmatrix Oct 4, 2024
31417c6
Merge branch 'main' into Media3
ne0rrmatrix Oct 15, 2024
2b430f2
Merge branch 'main' into Media3
ne0rrmatrix Oct 15, 2024
46bd46b
Merge branch 'main' into Media3
ne0rrmatrix Oct 16, 2024
1f2a35c
Merge branch 'main' into Media3
ne0rrmatrix Oct 20, 2024
b2fbdad
Merge branch 'main' into Media3
ne0rrmatrix Oct 24, 2024
ceae648
Make Bound Service immutable
ne0rrmatrix Oct 31, 2024
0d0e241
Update bound service connection to not use private set.
ne0rrmatrix Oct 31, 2024
2825a67
Merge branch 'main' into Media3
ne0rrmatrix Nov 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<toolkit:MediaElement
HeightRequest="200"
x:Name="MediaElement"
ShouldAutoPlay="True"
ShouldAutoPlay="False"
ShouldShowPlaybackControls="True"
Source="{Binding Source, Mode=OneTime}" />
<Label TextColor="White"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<toolkit:MediaElement
HeightRequest="200"
x:Name="MediaElement"
ShouldAutoPlay="True"
ShouldAutoPlay="False"
ShouldShowPlaybackControls="True"
Source="{Binding Source, Mode=OneTime}" />
<Label TextColor="White"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
android:supportsRtl="true">
<service android:name="communityToolkit.maui.media.services" android:stopWithTask="true" android:exported="false" android:enabled="true"
android:foregroundServiceType="mediaPlayback">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON"/>
</intent-filter>
<intent-filter>
<action android:name="androidx.media3.session.MediaSessionService"/>
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,8 @@
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.Contains('-android'))">
<PackageReference Include="Xamarin.AndroidX.Camera.View" Version="1.3.1.1" />
<PackageReference Include="Xamarin.AndroidX.Camera.Camera2" Version="1.3.1.1" />

<!-- Xamarin.AndroidX.Camera 1.3.1.1 depends on Xamarin.AndroidX.Lifecycle.LiveData 2.7.0.1:
https://www.nuget.org/packages/Xamarin.AndroidX.Camera.Core/#dependencies-body-tab
However, Dotnet MAUI still implicitly references Xamarin.AndroidX.Lifecycle.LiveData 2.6.1.3:
https://github.com/dotnet/maui/blob/main/eng/AndroidX.targets
This causes build error "Detected package downgrade":
https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1605
Workaround: add a package reference to the higher version of the package. Possibly can be removed when MAUI bumps the implicit reference version.
-->
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.7.0.1" />

<!--Adding the above package reference requires Workaround for https://github.com/xamarin/AndroidX/issues/800#issuecomment-1774639627 -->
<!-- Tracking issue https://github.com/xamarin/AndroidX/issues/764 -->
<PackageReference Include="Xamarin.AndroidX.Collection" Version="1.4.0.1" />
<PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.4.0.1" />
Comment on lines -56 to -70
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to a separate PR since it not related to CommunityToolkit.Maui.MediaElement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try reverting the changes. It was only modified so that transient dependancies did not clash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just looked at the code and was unable to find the referenced code. It has been removed. Not sure when. Can you try updating your local source.

<PackageReference Include="Xamarin.AndroidX.Camera.View" Version="1.3.4.2" />
ne0rrmatrix marked this conversation as resolved.
Show resolved Hide resolved
<PackageReference Include="Xamarin.AndroidX.Camera.Camera2" Version="1.3.4.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CommunityToolkit.Maui.Core.Handlers;
using CommunityToolkit.Maui.Core.Views;
using CommunityToolkit.Maui.Views;

namespace CommunityToolkit.Maui;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,38 @@
</PropertyGroup>

<ItemGroup>
<None Include="..\..\build\nuget.png" PackagePath="icon.png" Pack="true"/>
<None Include="ReadMe.txt" pack="true" PackagePath="."/>
<None Include="..\..\build\nuget.png" PackagePath="icon.png" Pack="true" />
<None Include="ReadMe.txt" pack="true" PackagePath="." />
</ItemGroup>

<ItemGroup>
<None Include="..\CommunityToolkit.Maui.MediaElement.Analyzers\bin\$(Configuration)\netstandard2.0\CommunityToolkit.Maui.MediaElement.Analyzers.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
<None Include="..\CommunityToolkit.Maui.MediaElement.Analyzers.CodeFixes\bin\$(Configuration)\netstandard2.0\CommunityToolkit.Maui.MediaElement.Analyzers.CodeFixes.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false"/>
<None Include="..\CommunityToolkit.Maui.MediaElement.Analyzers\bin\$(Configuration)\netstandard2.0\CommunityToolkit.Maui.MediaElement.Analyzers.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
<None Include="..\CommunityToolkit.Maui.MediaElement.Analyzers.CodeFixes\bin\$(Configuration)\netstandard2.0\CommunityToolkit.Maui.MediaElement.Analyzers.CodeFixes.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.Contains('-android'))">
<PackageReference Include="Xam.Plugins.Android.ExoPlayer" Version="[2.19.1,)"/>
<PackageReference Include="Xam.Plugins.Android.ExoPlayer.Transformer" Version="[2.19.1,)"/>
<PackageReference Include="Xam.Plugins.Android.ExoPlayer.MediaSession" Version="[2.19.1,)"/>
<PackageReference Include="Xamarin.AndroidX.Media3.ExoPlayer" Version="1.3.1.1" />
<PackageReference Include="Xamarin.AndroidX.Media3.Common" Version="1.3.1.1" />
<PackageReference Include="Xamarin.AndroidX.Media3.UI" Version="1.3.1.1" />
<PackageReference Include="Xamarin.AndroidX.Media3.ExoPlayer.Rtsp" Version="1.3.1.1" />
<PackageReference Include="Xamarin.AndroidX.Media3.ExoPlayer.Hls" Version="1.3.1.1" />
<PackageReference Include="Xamarin.AndroidX.Media3.ExoPlayer.Dash" Version="1.3.1.1" />
<PackageReference Include="Xamarin.AndroidX.Media3.Session" Version="1.3.1.1" />

<!--Adding the above package reference requires Workaround for https://github.com/xamarin/AndroidX/issues/800#issuecomment-1774639627 -->
<!-- Tracking issue https://github.com/xamarin/AndroidX/issues/764 -->
<PackageReference Include="Xamarin.AndroidX.Lifecycle.LiveData" Version="2.8.5.1" />

<!-- Should match version of the referenced 'Xamarin.AndroidX.Collection' package -->
<PackageReference Include="Xamarin.AndroidX.Collection.Jvm" Version="1.4.3.1" />
<PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.4.3.1" />

<!-- Should match version of the referenced 'Xamarin.AndroidX.Activity' package -->
<PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.9.2.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiPackageVersion)" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommunityToolkit.Maui.Core.Views;
using CommunityToolkit.Maui.Primitives;
using CommunityToolkit.Maui.Views;
using Microsoft.Maui.Handlers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,15 @@
/// <summary>
/// Represents event data for when media has failed loading or playing.
/// </summary>
public sealed class MediaFailedEventArgs : EventArgs
/// <remarks>
/// Initializes a new instance of the <see cref="MediaFailedEventArgs"/> class.
/// </remarks>
/// <param name="errorMessage">An error message providing more information for this event.</param>
public sealed class MediaFailedEventArgs(string errorMessage) : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="MediaFailedEventArgs"/> class.
/// </summary>
/// <param name="errorMessage">An error message providing more information for this event.</param>
public MediaFailedEventArgs(string errorMessage)
{
ErrorMessage = errorMessage;
}

/// <summary>
/// Gets a description of why the media failed to load and/or play.
/// </summary>
public string ErrorMessage { get; }
public string ErrorMessage { get; } = errorMessage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
/// <summary>
/// Represents event data for when media position has changed.
/// </summary>
public sealed class MediaPositionChangedEventArgs : EventArgs
/// <remarks>
/// Initializes a new instance of the <see cref="MediaPositionChangedEventArgs"/> class.
/// </remarks>
/// <param name="position">The position associated to this event.</param>
public sealed class MediaPositionChangedEventArgs(TimeSpan position) : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="MediaPositionChangedEventArgs"/> class.
/// </summary>
/// <param name="position">The position associated to this event.</param>
public MediaPositionChangedEventArgs(TimeSpan position)
{
Position = position;
}

/// <summary>
/// Gets the position the media has progressed to.
/// </summary>
public TimeSpan Position { get; }
public TimeSpan Position { get; } = position;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,20 @@
/// <summary>
/// Represents event data for when media state has changed.
/// </summary>
public sealed class MediaStateChangedEventArgs : EventArgs
/// <remarks>
/// Initializes a new instance of the <see cref="MediaStateChangedEventArgs"/> class.
/// </remarks>
/// <param name="previousState">The previous state.</param>
/// <param name="newState">The new state.</param>
public sealed class MediaStateChangedEventArgs(MediaElementState previousState, MediaElementState newState) : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="MediaStateChangedEventArgs"/> class.
/// </summary>
/// <param name="previousState">The previous state.</param>
/// <param name="newState">The new state.</param>
public MediaStateChangedEventArgs(MediaElementState previousState, MediaElementState newState)
{
PreviousState = previousState;
NewState = newState;
}

/// <summary>
/// Gets the previous state that the <see cref="Core.IMediaElement"/> instance is transitioning from.
/// </summary>
public MediaElementState PreviousState { get; }
public MediaElementState PreviousState { get; } = previousState;

/// <summary>
/// Gets the new state that the <see cref="Core.IMediaElement"/> instance is transitioning to.
/// </summary>
public MediaElementState NewState { get; }
public MediaElementState NewState { get; } = newState;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using AndroidX.Media3.UI;

namespace CommunityToolkit.Maui.Primitives;

public sealed class PlayerViewChangedEventArgs(PlayerView playerView) : EventArgs
{
public PlayerView UpdatedPlayerView { get; } = playerView;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
/// <summary>
/// Represents event data for when a seek operation is requested on media.
/// </summary>
sealed class MediaSeekRequestedEventArgs : EventArgs
/// <remarks>
/// Initializes a new instance of the <see cref="MediaSeekRequestedEventArgs"/> class.
/// </remarks>
/// <param name="requestedPosition">The requested position to seek to.</param>
sealed class MediaSeekRequestedEventArgs(TimeSpan requestedPosition) : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="MediaSeekRequestedEventArgs"/> class.
/// </summary>
/// <param name="requestedPosition">The requested position to seek to.</param>
public MediaSeekRequestedEventArgs(TimeSpan requestedPosition)
{
RequestedPosition = requestedPosition;
}

/// <summary>
/// Gets the requested position to seek to.
/// </summary>
public TimeSpan RequestedPosition { get; }
public TimeSpan RequestedPosition { get; } = requestedPosition;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Android.OS;
using CommunityToolkit.Maui.Media.Services;

namespace CommunityToolkit.Maui.Services;

class BoundServiceBinder(MediaControlsService mediaControlsService) : Binder
{
public MediaControlsService? Service { get; private set; } = mediaControlsService;
pictos marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Android.Content;
using Android.OS;
using CommunityToolkit.Maui.Core.Views;

namespace CommunityToolkit.Maui.Services;
class BoundServiceConnection(MediaManager mediaManager) : Java.Lang.Object, IServiceConnection
{
public MediaManager? Activity { get; private set; } = mediaManager;

public bool IsConnected { get; private set; } = false;

public BoundServiceBinder? Binder { get; private set; } = null;

void IServiceConnection.OnServiceConnected(ComponentName? name, IBinder? service)
{
Binder = service as BoundServiceBinder;
IsConnected = Binder is not null;
Activity?.UpdatePlayer();
}

void IServiceConnection.OnServiceDisconnected(ComponentName? name)
{
IsConnected = false;
Binder = null;
}
}
Loading