Xamarin iOS:如何在AvPlayer中隐藏搜索栏?

时间:2019-06-13 14:43:52

标签: xamarin.ios

我正在使用AvPlayer在xamarin ios中构建应用程序。如何隐藏搜索栏?

_playerViewController = new CustomAVPlayerViewController();
_player = new AVPlayer();
_playerViewController.Player = _player;
SetNativeControl(_playerViewController.View);


public class CustomAVPlayerViewController: AVPlayerViewController
    {
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
        }
    }

1 个答案:

答案 0 :(得分:0)

如果您不想显示控件或要高度自定义外观,建议您使用AVPlayerLayer

public class CustomPlayerRenderer : ViewRenderer<CustomPlayer, UIView>
{

    AVPlayer _player;
    AVPlayerLayer _playerLayer;
    protected override void OnElementChanged(ElementChangedEventArgs<CustomPlayer1> e)
    {
        base.OnElementChanged(e);

        if (Control == null)
        {
            _player = new AVPlayer(new NSUrl(NSBundle.MainBundle.PathForResource("sample.mp4", null), false));
            _playerLayer = AVPlayerLayer.FromPlayer(_player);

            UIView view = new UIView();
            view.Layer.AddSublayer(_playerLayer);

            SetNativeControl(view);

            //_player.Play();
            // Add custom controls as you want on this view
        }
    }

    public override void Draw(CGRect rect)
    {
        base.Draw(rect);

        _playerLayer.Frame = rect;
    }
}