public BCOVSource FindDashSource(BCOVSource[] sources, bool withHTTPS)
        {
            //We prioritize HLS v3 > DASH > MP4
            var filteredSources = new List <BCOVSource>();

            foreach (var source in sources)
            {
                if (withHTTPS == true && source.Url.AbsoluteString.Contains("https://"))
                {
                    filteredSources.Add(source);
                }
                else
                {
                    if (source.Url.AbsoluteString.Contains("http://"))
                    {
                        filteredSources.Add(source);
                    }
                }
            }

            BCOVSource dashSource = null;

            foreach (var source in filteredSources)
            {
                var deliveryMethod = source.DeliveryMethod;

                if (deliveryMethod.Equals("application/dash+xml"))
                {
                    dashSource = source;
                }
            }

            if (dashSource != null)
            {
                Console.WriteLine("hlsSource");
                Console.WriteLine(dashSource.Url.AbsoluteString);
                return(dashSource);
            }

            return(null);
        }
        public BCOVSource FindPreferredSource(BCOVSource[] sources, bool withHTTPS)
        {
            //We prioritize HLS v3 > DASH > MP4
            var filteredSources = new List <BCOVSource>();

            foreach (var source in sources)
            {
                if (withHTTPS == true && source.Url.AbsoluteString.Contains("https://"))
                {
                    filteredSources.Add(source);
                }
                else
                {
                    if (source.Url.AbsoluteString.Contains("http://"))
                    {
                        filteredSources.Add(source);
                    }
                }
            }

            BCOVSource hlsSource = null;
            BCOVSource mp4Source = null;

            foreach (var source in filteredSources)
            {
                var urlString      = source.Url.AbsoluteString;
                var deliveryMethod = source.DeliveryMethod;

                if (urlString.Contains("ac-3_avc1_ec-3"))
                {
                    hlsSource = source;
                    break;
                }

                if (urlString.Contains("hls/v3") && deliveryMethod.Equals("application/x-mpegURL"))
                {
                    hlsSource = source;
                    break;
                }

                if (deliveryMethod.Equals("video/mp4"))
                {
                    mp4Source = source;
                }
            }

            if (hlsSource != null)
            {
                Console.WriteLine("hlsSource");
                Console.WriteLine(hlsSource.Url.AbsoluteString);
                return(hlsSource);
            }

            if (mp4Source != null)
            {
                Console.WriteLine("mp4Source");
                Console.WriteLine(mp4Source.Url.AbsoluteString);
                return(mp4Source);
            }

            return(null);
        }
        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();
        }