-
Notifications
You must be signed in to change notification settings - Fork 492
Expand file tree
/
Copy pathMediaElementHandler.android.cs
More file actions
51 lines (46 loc) · 1.81 KB
/
MediaElementHandler.android.cs
File metadata and controls
51 lines (46 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using CommunityToolkit.Maui.Core.Views;
using CommunityToolkit.Maui.Views;
using Microsoft.Maui.Handlers;
namespace CommunityToolkit.Maui.Core.Handlers;
public partial class MediaElementHandler : ViewHandler<MediaElement, MauiMediaElement>, IDisposable
{
/// <summary>
/// Maps the <see cref="IMediaElement.ShouldLoopPlayback"/> property between the abstract
/// <see cref="MediaElement"/> and platform counterpart.
/// </summary>
/// <param name="handler">The associated handler.</param>
/// <param name="mediaElement">The associated <see cref="MediaElement"/> instance.</param>
public static void ShouldLoopPlayback(MediaElementHandler handler, MediaElement mediaElement)
{
handler.MediaManager?.UpdateShouldLoopPlayback();
}
protected override MauiMediaElement CreatePlatformView()
{
MediaManager ??= new(MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} cannot be null"),
VirtualView,
Dispatcher.GetForCurrentThread() ?? throw new InvalidOperationException($"{nameof(IDispatcher)} cannot be null"));
var playerView = MediaManager.CreatePlatformView(VirtualView.AndroidViewType);
return new(Context, playerView);
}
protected override async void ConnectHandler(MauiMediaElement platformView)
{
base.ConnectHandler(platformView);
if (platformView is null)
{
throw new InvalidOperationException($"{nameof(platformView)} cannot be null");
}
if (MediaManager is null)
{
throw new InvalidOperationException($"{nameof(MediaManager)} cannot be null");
}
var mediaController = await MediaManager.CreateMediaController();
platformView.SetView(mediaController);
await MediaManager.UpdateSource();
}
protected override void DisconnectHandler(MauiMediaElement platformView)
{
platformView.Dispose();
Dispose();
base.DisconnectHandler(platformView);
}
}