示例#1
0
        public void SwitchToRemotePlayback()
        {
            avp.Pause();
            CreateMediaInfo();
            mLocation = PlaybackLocation.REMOTE;

            //ios sample does it via queue, we'll straight up load
            var castSession = CastContext.SharedInstance.SessionManager.CurrentCastSession;
            RemoteMediaClient remoteMediaClient = null;
            var options = new MediaLoadOptions();

            //options.PlayPosition = currentprogress;
            options.Autoplay = true;

            if (castSession != null)
            {
                remoteMediaClient = castSession.RemoteMediaClient;
                remoteMediaClient.MediaQueue?.Clear();
            }

            if (castSession != null && remoteMediaClient != null && castMediaInfo != null)
            {
                remoteMediaClient.LoadMedia(castMediaInfo, options);
            }
            else
            {
                Console.WriteLine("ERROR in SwitchToRemotePlayback");
            }

            ClosePage();
        }
示例#2
0
 public void CastClosePlayerActivity()
 {
     //things to happen when player page closes because connected to cast
     mLocation = PlaybackLocation.REMOTE;
     videoView.StopPlayback();
     this.Finish();
 }
示例#3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            RequestedOrientation = Android.Content.PM.ScreenOrientation.Landscape;
            base.OnCreate(savedInstanceState);

            castSessionManagerListener = new CastSessionManagerListener(this);
            castContext = CastContext.GetSharedInstance(this);
            castSession = castContext.SessionManager.CurrentCastSession;
            castContext.SessionManager.AddSessionManagerListener(castSessionManagerListener);

            //setup layout and video data
            SetContentView(Resource.Layout.playerPageLayout);
            mediaInfo = chromecastService.Value.GetPlaybackAsset();

            //TITLE
            assetTitle          = FindViewById <TextView>(Resource.Id.assetTitle);
            assetTitle.Text     = mediaInfo.DisplayName;
            assetTitle.TextSize = 20;

            //BACKBUTTON
            backButton        = FindViewById <Button>(Resource.Id.backButton);
            backButton.Click += BackButton_Click;

            //Cast Button setup
            castButton = (MediaRouteButton)FindViewById(Resource.Id.media_route_button);
            CastButtonFactory.SetUpMediaRouteButton(ApplicationContext, castButton);

            //VideoPlayer Source
            videoView = FindViewById <VideoView>(Resource.Id.video_view);
            var videoURL = Android.Net.Uri.Parse(mediaInfo.SourceURL);

            mController = new Android.Widget.MediaController(this);
            mController.SetAnchorView(videoView);
            videoView.SetVideoURI(videoURL);
            videoView.SetMediaController(mController);

            if (mLocation == PlaybackLocation.LOCAL)
            {
                videoView.Start();
            }
            else
            {
                castSession = castContext.SessionManager.CurrentCastSession;
                if ((castSession != null) && (castSession.IsConnected == true))
                {
                    //setup media to send to cast receiver
                    mLocation = PlaybackLocation.REMOTE;
                    var test = castContext.SessionManager.CurrentCastSession;

                    //call/initialize customCastMediaManager if needed. this sample uses default things
                }
            }
        }
示例#4
0
        protected override void OnElementChanged(VisualElementChangedEventArgs e)
        {
            base.OnElementChanged(e);



            if (e.OldElement != null || Element == null)
            {
                return;
            }

            try
            {
                SetupChromecastThings();
                SetupUserInterface();
                StartVideoPlayback();
                currentPage = Element;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"\t\t\tERROR: {ex.Message}");
            }

            void StartVideoPlayback()
            {
                var hasConnection = sessionManager.HasConnectedSession;

                if (hasConnection)
                {
                    mLocation = PlaybackLocation.REMOTE;
                    SwitchToRemotePlayback();
                    ClosePage();
                }

                if (mLocation == PlaybackLocation.LOCAL)
                {
                    avp.Play();
                }
            }

            void SetupUserInterface()
            {
                url          = NSUrl.FromString(mediaInfo.SourceURL);
                avp          = new AVPlayer(url);
                avpvc        = new AVPlayerViewController();
                avpvc.Player = avp;
                AddChildViewController(avpvc);
                avpvc.View.Frame            = new CGRect(0, 100, 375, 300);
                avpvc.ShowsPlaybackControls = true;
                View.AddSubview(avpvc.View);

                var castButton = new UICastButton(new CGRect(50, 20, 24, 24));

                View.AddSubview(castButton);
            }

            void SetupChromecastThings()
            {
                //setup Cast session manager
                sessionManager             = CastContext.SharedInstance.SessionManager;
                xamaSessionManagerListener = new XamSessionManagerListener(this);
                sessionManager.AddListener(xamaSessionManagerListener);

                //castMediaController
                castMediaController          = new UIMediaController();
                castMediaController.Delegate = new XamMediaControllerDelegate();
            }
        }