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 } } }
private void OnApplicationConnected(CastSession castSession) { Debug.WriteLine("CAST SESSION :: " + castSession); if (playeractivity.videoView.IsPlaying) { playeractivity.videoView.Pause(); } playeractivity.mLocation = PlaybackLocation.REMOTE; playeractivity.LoadRemoteMedia(); //do anything else here like navigate back to main page playeractivity.CastClosePlayerActivity(); }
public void LoadRemoteMedia() { castSession = castContext.SessionManager.CurrentCastSession; if (castSession == null) { Debug.WriteLine("NO CAST SESSION"); return; } var remoteClient = castSession.RemoteMediaClient; if (remoteClient != null) { remoteClient.Load(CreateMediaInfo(), true); remoteClient.Seek(videoView.CurrentPosition); remoteClient.Play(); //CastClosePlayerActivity(); } }