-
Notifications
You must be signed in to change notification settings - Fork 5
/
MyMiniPlayerRenderer.cs
71 lines (61 loc) · 2.51 KB
/
MyMiniPlayerRenderer.cs
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Diagnostics;
using CoreGraphics;
using Google.Cast;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
using XamCast;
using XamCast.iOS.Renderers;
[assembly: ExportRenderer(typeof(MyMiniPlayer), typeof(MyMiniPlayerRenderer))]
namespace XamCast.iOS.Renderers
{
public class MyMiniPlayerRenderer : ViewRenderer<MyMiniPlayer, UIView>
{
UIMiniMediaControlsViewController miniMediaControlsViewController;
UIView miniMediaControlsContainerView;
protected override void OnElementChanged(ElementChangedEventArgs<MyMiniPlayer> e)
{
base.OnElementChanged(e);
if (e.NewElement != null)
{
if (Control == null)
{
var castContext = CastContext.SharedInstance;
miniMediaControlsViewController = castContext.CreateMiniMediaControlsViewController();
miniMediaControlsViewController.Delegate = new XamGoogleCastMiniControllerDelegate(this);
miniMediaControlsContainerView = new UIView();
miniMediaControlsContainerView.Frame = new CGRect(0, 0, 400, 45);
miniMediaControlsViewController.View.Frame = miniMediaControlsContainerView.Bounds;
miniMediaControlsContainerView.AddSubview(miniMediaControlsViewController.View);
UpdateControlBarsVisibility();
SetNativeControl(miniMediaControlsContainerView);
}
}
}
public class XamGoogleCastMiniControllerDelegate : UIMiniMediaControlsViewControllerDelegate
{
MyMiniPlayerRenderer playerRenderer;
public XamGoogleCastMiniControllerDelegate(MyMiniPlayerRenderer pageR)
{
this.playerRenderer = pageR;
}
public override void ShouldAppear(UIMiniMediaControlsViewController miniMediaControlsViewController, bool shouldItAppear)
{
playerRenderer.UpdateControlBarsVisibility();
}
}
public void UpdateControlBarsVisibility()
{
Debug.WriteLine("miniMediaControlsViewController Active : " + miniMediaControlsViewController.Active);
if (miniMediaControlsViewController.Active)
{
miniMediaControlsContainerView.Hidden = false;
}
else
{
miniMediaControlsContainerView.Hidden = true;
}
}
}
}