void CastVideo(object sender, EventArgs e)
        {
            // Show Alert if not connected
            if (DeviceManager == null || !DeviceManager.IsConnected)
            {
                new UIAlertView("Not Connected", "Please connect to a cast device", null, "Ok", null).Show();
                return;
            }

            // Define Media metadata
            var metadata = new MediaMetadata();

            metadata.SetString("Big Buck Bunny (2008)", MetadataKey.Title);
            metadata.SetString("Big Buck Bunny tells the story of a giant rabbit with a heart bigger than " +
                               "himself. When one sunny day three rodents rudely harass him, something " +
                               "snaps... and the rabbit ain't no bunny anymore! In the typical cartoon " +
                               "tradition he prepares the nasty rodents a comical revenge.",
                               MetadataKey.Subtitle);
            metadata.AddImage(new Image(new NSUrl("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg"), 480, 360));

            // define Media information
            var mediaInformation = new MediaInformation("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
                                                        MediaStreamType.None, "video/mp4", metadata, 0, null);

            // cast video
            MediaControlChannel.LoadMedia(mediaInformation, true, 0);
        }
        // Builds all the information to be sent to Cast device.
        MediaInformation BuildMediaInformation(int categoryIndexSelected, int videoIndexSelected)
        {
            var category = categories [categoryIndexSelected];
            var video    = category.Videos [videoIndexSelected];

            var metadata = new MediaMetadata(MediaMetadataType.Movie);

            metadata.SetString(video.Title, MetadataKey.Title);
            metadata.SetString(video.Subtitle, MetadataKey.Subtitle);
            metadata.SetString(video.Studio, MetadataKey.Studio);

            var imageUrl = new NSUrl($"{category.ImagesBaseUrl}{video.ImageUrl}");

            metadata.AddImage(new Image(imageUrl, 480, 720));

            var posterUrl = new NSUrl($"{category.ImagesBaseUrl}{video.PosterUrl}");

            metadata.AddImage(new Image(posterUrl, 780, 1200));

            string videoUrl = string.Empty;

            var tracks = new List <MediaTrack> ();

            video.Tracks = video.Tracks ?? new List <Track> ();

            foreach (var track in video.Tracks)
            {
                tracks.Add(new MediaTrack(
                               int.Parse(track.Id),
                               $"{category.TracksBaseUrl}{track.ContentId}",
                               track.Type,
                               MediaTrackType.Text,
                               MediaTextTrackSubtype.Captions,
                               track.Name,
                               track.Language,
                               null));
            }

            foreach (var source in video.Sources)
            {
                if (!source.Type.Equals("mp4"))
                {
                    continue;
                }

                videoUrl = $"{category.Mp4BaseUrl}{source.Url}";
            }

            var mediaInformation = new MediaInformation(videoUrl,
                                                        MediaStreamType.Buffered,
                                                        "video/mp4", metadata,
                                                        video.Duration,
                                                        tracks.ToArray(),
                                                        null,
                                                        null);

            return(mediaInformation);
        }
Exemple #3
0
        //CreateCastMedia
        public void CreateMediaInfo()
        {
            var videoUrl = mediaInfo.SourceURL;
            var vname    = mediaInfo.DisplayName;
            var extra    = new string[] { "{", "}" };


            var metaData = new MediaMetadata(MediaMetadataType.Generic);

            metaData.SetString(mediaInfo.DisplayName, MetadataKey.Title);
            metaData.SetString("Hello World on Fridays!", MetadataKey.Subtitle);


            var builder = new MediaInformationBuilder();

            builder.ContentId  = videoUrl;
            builder.StreamType = MediaStreamType.Buffered;
            builder.Metadata   = metaData;

            castMediaInfo = builder.Build();
        }
        public void CreateMediaInfo(BCOVVideo video)
        {
            BCOVSource source = null;

            // Don't restart the current video
            if (currentVideo != null)
            {
                didContinueCurrentVideo = currentVideo.IsEqual(video);
                if (didContinueCurrentVideo)
                {
                    return;
                }
            }

            suitableSourceNotFound = false;

            // Try to find an HTTPS source first
            source = FindDashSource(video.Sources, true);

            if (source == null)
            {
                source = FindDashSource(video.Sources, false);
            }

            // If no source was able to be found, let the delegate know
            // and do not continue
            if (source == null)
            {
                suitableSourceNotFound = true;
                gcmDelegate.SuitableSourceNotFound();
                return;
            }

            currentVideo = video;

            var videoUrl       = source.Url.AbsoluteString;
            var vname          = video.Properties["name"];
            var durationNumber = video.Properties["duration"];

            var metaData = new MediaMetadata(MediaMetadataType.Generic);

            metaData.SetString(vname.ToString(), "kGCKMetadataKeyTitle");

            var poster    = video.Properties["poster"].ToString();
            var posterUrl = new NSUrl(poster);

            metaData.AddImage(new Image(posterUrl, (nint)posterImageSize.Width, (nint)posterImageSize.Height));

            //TODO Implement this logic for closed caption cast
            //var mediaTracks = new List<MediaTrack>();
            //var textTracks = video.Properties["text_tracks"];
            //var trackIndentifier = 0;
            //foreach (var text in textTracks)
            //{
            //    trackIndentifier += 1;
            //    string src, lang, name, contentType, kind;
            //    if (text.Key.ToString() == "src")
            //        src = text.
            //    //string lang = text["srclang"] as string;
            //    //var name = text["label"] as string;
            //    //var contentType = text["mime_type"] as string;
            //}


            var builder = new MediaInformationBuilder();

            builder.ContentId      = videoUrl;
            builder.StreamType     = MediaStreamType.Unknown;
            builder.ContentType    = source?.DeliveryMethod;
            builder.Metadata       = metaData;
            builder.StreamDuration = (double)(durationNumber as NSNumber);
            //TODO uncomment this for closed caption cast
            //builder.MediaTracks = mediaTracks;

            castMediaInfo = builder.Build();
        }
        void SimpleCastBtn_TouchUpInside(object sender, EventArgs e)
        {
            //Show Alert if not connected
             if (DeviceManager == null || DeviceManager.ConnectionState != ConnectionState.Connected)
             {
                new UIAlertView ("Not Connected", "Please connect to a cast device", null, "Ok", null).Show ();
                return;
             }

             // Define Media metadata
             var metadata = new MediaMetadata ();
             metadata.SetString ("Big Buck Bunny (2008)", MetadataKey.Title);
             metadata.SetString ("Big Buck Bunny tells the story of a giant rabbit with a heart bigger than " +
                "himself. When one sunny day three rodents rudely harass him, something " +
                "snaps... and the rabbit ain't no bunny anymore! In the typical cartoon " +
                "tradition he prepares the nasty rodents a comical revenge.",
                MetadataKey.Subtitle);

             metadata.AddImage (new Image (new NSUrl ("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/images/BigBuckBunny.jpg"), 480, 360));

             // define Media information
             var mediaInformation = new MediaInformation ("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4",
                MediaStreamType.None, "video/mp4", metadata, 0, null);
             // cast video
             MediaControlChannel.LoadMedia (mediaInformation, true, 0);
        }