public ScriptPlaylistItem(PlaylistItem item)
        {
            foreach (var marker in item.TimelineMarkers)
            {
                _markers.Add(new ScriptMediaMarker(marker));
            }
            FileSize = item.FileSize;
            FrameRate = item.FrameRate;
            JumpToLive = item.JumpToLive;
            if (MediaSource != null)
            {
                MediaSource = item.MediaSource.ToString();
            }
            if (ThumbSource != null)
            {
                ThumbSource = item.ThumbSource.ToString();
            }
            Description = item.Description;
            Title = item.Title;
            VideoStretchMode = item.VideoStretchMode.ToString();
            VideoWidth = item.VideoWidth;
            VideoHeight = item.VideoHeight;
            if (item.S3DProperties == null)
            {
                ScriptS3DProperties = new ScriptS3DProperties();
            }
            else
            {
                ScriptS3DProperties = new ScriptS3DProperties(item.S3DProperties);
            }
			CustomMetadata = item.CustomMetadata;
        }
        private void TakeOffline(PlaylistItem playlistItem)
        {
            lock (_pendingOfflineTasks)
            {
                _pendingOfflineTasks.Add(playlistItem, new List<OfflineTask>());

                if (playlistItem.ThumbSource != null)
                {
                    QueueOfflineTask(playlistItem, playlistItem.ThumbSource, OfflineTaskType.DownloadFile);
                }

                foreach (var chapter in playlistItem.Chapters)
                {
                    if (chapter.ThumbSource != null)
                    {
                        QueueOfflineTask(playlistItem, chapter.ThumbSource, OfflineTaskType.DownloadFile);
                    }
                }

                if (playlistItem.MarkerResources != null)
                {
                    foreach (MarkerResource r in playlistItem.MarkerResources)
                    {
                        QueueOfflineTask(playlistItem, r.Source, OfflineTaskType.DownloadFile);
                    }
                }

                var mediaTaskType = playlistItem.DeliveryMethod == DeliveryMethods.AdaptiveStreaming
                                        ? OfflineTaskType.ProcessManifest
                                        : OfflineTaskType.DownloadFile;

                QueueOfflineTask(playlistItem, playlistItem.MediaSource, mediaTaskType);
            }

        }
        public OfflineTask(PlaylistItem playlistItem, OfflineTaskType type, Uri resourceLocation)
        {
            if (playlistItem == null) throw new ArgumentNullException("playlistItem");

            Type = type;
            ResourceLocation = resourceLocation;
            PlaylistItem = playlistItem;
        }
        public void Activate()
        {
            if (PhoneApplicationService.Current.State.ContainsKey(SelectedPlaylistItemStateKey))
            {
                var selectedPlaylistItemIndex = PhoneApplicationService.Current.State[SelectedPlaylistItemStateKey] as int?;

                if (selectedPlaylistItemIndex.HasValue)
                {
                    SelectedPlaylistItem = Playlist[selectedPlaylistItemIndex.Value];
                }
            }
        }
Пример #5
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            PlaylistItem item = new PlaylistItem();
            //item.MediaSource = new Uri("http://ecn.channel9.msdn.com/o9/content/smf/smoothcontent/bbbwp7/big buck bunny.ism/manifest");
            item.MediaSource = new Uri("C:\\Users\\piers.williams\\Downloads\\dail.ism");
            item.DeliveryMethod = Microsoft.SilverlightMediaFramework.Plugins.Primitives.DeliveryMethods.AdaptiveStreaming;
            strmPlayer.Playlist.Add(item);
            strmPlayer.Play();
        }
Пример #6
0
        private PlaylistItem(PlaylistItem playlistItem)
        {
            CustomMetadata = new MetadataCollection();
            MediaPluginRequiredMetadata = new MetadataCollection();
            playlistItem.MediaPluginRequiredMetadata
                        .Select(i => i.Clone())
                        .ForEach(MediaPluginRequiredMetadata.Add);
			playlistItem.CustomMetadata
						.Select(i => i.Clone())
						.ForEach(CustomMetadata.Add);
            InterstitialAdvertisements = playlistItem.InterstitialAdvertisements
                                                     .Select(i => i.Clone())
                                                     .ToList();

            TimelineMarkers = playlistItem.TimelineMarkers
                                          .Select(i => i.Clone())
                                          .ToList();

            Chapters = playlistItem.Chapters
                                   .Select(i => i.Clone())
                                   .ToList();

            Captions = playlistItem.Captions.ToList();

            playlistItem.MarkerResources.IfNotNull(i => MarkerResources = i.Select(j => j.Clone()).ToList());
            playlistItem.PreRollAdvertisement.IfNotNull(i => PreRollAdvertisement = i.Clone());
            playlistItem.PostRollAdvertisement.IfNotNull(i => PostRollAdvertisement = i.Clone());

            DeliveryMethod = playlistItem.DeliveryMethod;
			S3DProperties = playlistItem.S3DProperties;
            FrameRate = playlistItem.FrameRate;
            LiveDvrRequired = playlistItem.LiveDvrRequired;
            MediaSource = playlistItem.MediaSource;
            SelectedAudioStreamLanguage = playlistItem.SelectedAudioStreamLanguage;
            SelectedAudioStreamName = playlistItem.SelectedAudioStreamName;
            SelectedCaptionStreamLanguage = playlistItem.SelectedCaptionStreamLanguage;
            SelectedCaptionStreamName = playlistItem.SelectedCaptionStreamName;
            StartPosition = playlistItem.StartPosition;
            StreamSource = playlistItem.StreamSource;
            Title = playlistItem.Title;
            Description = playlistItem.Description;
            ThumbSource = playlistItem.ThumbSource;
            FileSize = playlistItem.FileSize;
            JumpToLive = playlistItem.JumpToLive;
            VideoHeight = playlistItem.VideoHeight;
            VideoWidth = playlistItem.VideoWidth;
            VideoStretchMode = playlistItem.VideoStretchMode;
        }
 void Player_Loaded(object sender, RoutedEventArgs e)
 {
     Player.Back += new EventHandler(Player_Back);
     var playlist = new ObservableCollection<PlaylistItem>();
     var playlistItem = new PlaylistItem()
     {
         MediaSource = new Uri("http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8"),
         MediaAssetId = String.Format("http://gaiamtv.com/TV/{0}", "HLSPlayerPage"),
         MediaType = "application/x-mpegURL",
         //LiveDvrRequired = false,
         //JumpToLive = true,
          DeliveryMethod= Microsoft.SilverlightMediaFramework.Plugins.Primitives.DeliveryMethods.AdaptiveStreaming
     };
     playlist.Add(playlistItem);
     Player.Playlist = playlist;
     Player.Play();
 }
 public void playerStart()
 {
     try
     {
         var playlist = new ObservableCollection<PlaylistItem>();
         var playlistItem = new PlaylistItem
         {
             MediaSource = new Uri(newStream)
         };
         playlistItem.DeliveryMethod = DeliveryMethods.AdaptiveStreaming;
         playlist.Add(playlistItem);
         Playlist = playlist;
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
     }
 }
Пример #9
0
 private void LoadVideo()
 {
     if (matchInfo.linkType == WillowLinkType.onDemandVideo)
         {
             videoPlayer.Playlist[0].MediaSource = new Uri(WillowUtils.getModifiedURL(playlist.First()));
             for (int i = 1; i < playlist.Count; i++)
             {
                 PlaylistItem pitem = new PlaylistItem();
                 pitem.DeliveryMethod = Microsoft.SilverlightMediaFramework.Plugins.Primitives.DeliveryMethods.AdaptiveStreaming;
                 pitem.MediaSource = new Uri(WillowUtils.getModifiedURL(playlist[i]));
                 videoPlayer.Playlist.Add(pitem);
             }
             //TODO::make playlist
         }
         else if (matchInfo.matchId.CompareTo("999999") == 0)
         {
             videoPlayer.Playlist[0].MediaSource = new Uri(WillowUtils.getModifiedURL(matchInfo.videoUrl));
         }
         else
         {
             videoPlayer.Playlist[0].MediaSource = new Uri(matchInfo.videoUrl);
         }
 }
        protected virtual IMediaPlugin SelectMediaPlugin(PlaylistItem playlistItem)
        {
            IEnumerable<LooseMetadataLazy<IMediaPlugin, IMediaPluginMetadata>> results = PluginsManager.MediaPlugins;
            if (playlistItem.DeliveryMethod != DeliveryMethods.NotSpecified)
            {
                results = results.Where(i => i.LooseMetadata.ContainsKey("SupportedDeliveryMethods"));
                results = results.Where(i => (((DeliveryMethods)i.LooseMetadata["SupportedDeliveryMethods"]) & playlistItem.DeliveryMethod) != 0);
            }

            IEnumerable<LooseMetadataLazy<IMediaPlugin, IMediaPluginMetadata>> subResults;
            if (playlistItem.MediaType == null)
            {
                subResults = results.Where(i => !((string[])i.LooseMetadata["SupportedMediaTypes"]).Any());
            }
            else
            {
                subResults = results.Where(i => ((string[])i.LooseMetadata["SupportedMediaTypes"]).Contains(playlistItem.MediaType));
            }
            // make this filter forgiving. Ignore if it filtered out all media plugins
            if (subResults.Any())
            {
                results = subResults;
            }

            //If the media is live and we have implementations that support the live interface then
            //filter the list down to these implementations as they will provide
            //a better experience for the user, however, this is not a required to play the live media
            if (playlistItem.LiveDvrRequired)
            {
                results = results.Where(i => i.LooseMetadata.ContainsKey("SupportsLiveDvr"));
                results = results.Where(i => ((bool)i.LooseMetadata["SupportsLiveDvr"]));
            }

            //Favor Plugins that have already been instantiated
            LooseMetadataLazy<IMediaPlugin, IMediaPluginMetadata> result = results.Any(i => i.IsValueCreated)
                                                                                ? results.First(i => i.IsValueCreated)
                                                                                : results.FirstOrDefault();
            return result != null ? result.Value : null;
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            IDictionary<string, string> queryString = this.NavigationContext.QueryString;
            var playlist = new ObservableCollection<PlaylistItem>();
            PlaylistItem playlistItem = new PlaylistItem()
            {
                DeliveryMethod = Microsoft.SilverlightMediaFramework.Plugins.Primitives.DeliveryMethods.AdaptiveStreaming,
                MediaAssetId = "SSMESampleContent",
            };

            if (queryString.ContainsKey("LicenseServerURI"))
            {
                var licenseAcquirer = new Uri(queryString["LicenseServerURI"], UriKind.RelativeOrAbsolute);
            }

            if (queryString.ContainsKey("SourceURI"))
            {
                var source = new Uri(queryString["SourceURI"], UriKind.RelativeOrAbsolute);
                playlistItem.MediaSource = source;
                playlist.Add(playlistItem);
                Player.Playlist = playlist;
            }
            else
            {
                System.Diagnostics.Debug.Assert(false, "FullScreenPlayer.OnNavigatedTo: SourceURI is not set.");
                NavigationService.GoBack();
            }

            base.OnNavigatedTo(e);
        }
        private void Play()
        {
            if (playListUris == null) return;
            if (selectedIndex == -1) return;

            CreateNewSMFPlayer();
            if (player == null) return;

            for (var i = 0; i < playListUris.Count; i++) {
                var uri = playListUris[i];
                var playlistItem = new PlaylistItem {MediaSource = uri};
                player.Playlist.Add(playlistItem);
                if (i == selectedIndex)
                    player.CurrentPlaylistItem = playlistItem;
            }
            try {
                player.Play();
            }
            catch {
                GoogleAnalytics.EasyTracker.GetTracker().SendEvent("Download Error", "Video", player.CurrentPlaylistItem.MediaSource.Host, 0);
                PromptVideoNotFound();
            }
        }
Пример #13
0
 /// <summary>
 /// Helper function to add UAC ad schedule data to a playlist item
 /// </summary>
 /// <param name="item">The playlist item to modify</param>
 /// <param name="AdStream">A stream containing ad data the UAC can handle</param>
 public static void AddAdScheduleToPlaylistItem(PlaylistItem item, Stream AdStream)
 {
     item.CustomMetadata.Add(new Utilities.Metadata.MetadataItem() { Key = Key_AdUrl, Value = AdStream });
 }
Пример #14
0
        /// <summary>
        /// Add a piece of content with an ad stream or url to the smf player's playlist; internal.
        /// </summary>
        /// <param name="player">The smf player to add the content to</param>
        /// <param name="contentUrl">The url to the content</param>
        /// <param name="method">The delivery method for the content (adaptive or progressive)</param>
        /// <param name="adSchedule">The stream to the ad schedule</param>
        /// <param name="startTime">The time in the content where playback will begin</param>
        /// <param name="assetID">The asset ID of the content that is being played</param>
        internal static void AddContentWithAdToPlaylistInternal(SMFPlayer player, string contentUrl, DeliveryMethods method, object adSchedule, TimeSpan startTime, string assetID)
        {
            PlaylistItem item = new PlaylistItem()
            {
                StartPosition = startTime,
                MediaAssetId = assetID,
                DeliveryMethod = method,
                MediaSource = new Uri(contentUrl),
                CustomMetadata = new Utilities.Metadata.MetadataCollection()
                {
                    new Utilities.Metadata.MetadataItem() { Key = Key_AdUrl, Value = adSchedule }
                }
            };

            player.Playlist.Add(item);
        }
        private void OnCurrentPlaylistItemChanged(PlaylistItem previousPlaylistItem)
        {
            try
            {
                retryPending = false;
                var wasPlaySuspended = playSuspended;
                Stop();
                playSuspended = wasPlaySuspended;
                RestorePlayerDefaults();
                BitrateGraphElement.IfNotNull(i => i.Reset());
                FramerateGraphElement.IfNotNull(i => i.Reset());
                UpdateCurrentPlaylistItemSelection();
                previousPlaylistItem.IfNotNull(i => i.LicenseAcquirer = null);

                if (CurrentPlaylistItem != null)
                {
                    IsPosterVisible = !AutoPlay;

                    CurrentPlaylistItem.TimelineMarkers.ForEach(TimelineMarkers.Add);
                    CurrentPlaylistItem.Chapters.ForEach(Chapters.Add);

                    if (CurrentPlaylistItem.Captions.Any())
                    {
                        CurrentPlaylistItem.Captions.ForEach(Captions.Add);
                        _captionManager.CheckMarkerPositions(RelativeMediaPluginPosition, Captions, ignoreSearchWindow: true);
                    }

                    ActiveMediaPlugin = SelectMediaPlugin(CurrentPlaylistItem);
                    if (ActiveMediaPlugin != null)
                    {
                        ActiveMediaPlugin.Load();
                        SendLogEntry(KnownLogEntryTypes.PlaylistItemChanged, message: SilverlightMediaFrameworkResources.PlaylistItemChangedLogMessage);
                        OnPlaylistItemChanged();
                        SetChunkDownloadStrategy(CurrentPlaylistItem.ChunkDownloadStrategy);
                    }
                    else
                    {
                        SendLogEntry(KnownLogEntryTypes.UnableToLocateMediaPlugin, LogLevel.Warning, SilverlightMediaFrameworkResources.UnableToLocateMediaPluginLogMessage);
                        OnPlaylistItemChanged();
                    }
                }
                else
                {
                    MarkerProviders = null;
                    ActiveMediaPlugin = null;
                    SendLogEntry(message: SilverlightMediaFrameworkResources.PlaylistItemChangedLogMessage, type: KnownLogEntryTypes.PlaylistItemChanged);
                    OnPlaylistItemChanged();
                }
            }
            catch (Exception err)
            {
                string message = string.Format(SilverlightMediaFrameworkResources.GenericErrorOccurredLogMessage,
                                               "OnCurrentPlaylistItemChanged", err.Message);
                SendLogEntry(KnownLogEntryTypes.GeneralErrorOccurred, LogLevel.Error, message);
            }
        }
 public OfflineTask(PlaylistItem playlistItem, OfflineTaskType type)
     : this(playlistItem, type, null) { }
 private void ResetRetryInformation()
 {
     _firstRetryItem = null;
 }
 private void TryNextPlaylistItem()
 {
     bool canTryNext = true;
     if (_firstRetryItem == null)
     {
         _firstRetryItem = CurrentPlaylistItem;
     }
     else
     {
         canTryNext = (CurrentPlaylistItem != _firstRetryItem);
     }
     if (canTryNext)
     {
         GoToNextPlaylistItem();
     }
 }
        /// <summary>
        /// Selects a MediaPlugin plugin that can play a specified Playlist item.
        /// </summary>
        /// <remarks>
        /// The PlaylistItem passed to this method is used to determine which type of IMediaPlugin to return.
        /// If more than one plugin can play the Playlist item (based on the required capabilities it lists in its attributes), the first plugin found that matches that item's play requirements in used.
        /// For the selection of which plugin to use if several match the requirements, a plugin already instantiated will take precedence over other plugins.
        /// </remarks>
        /// <returns>
        /// An IMediaPlugin that can play the type of Playlist item passed as a parameter.
        /// </returns>
#if !WINDOWS_PHONE && !PROGRAMMATICCOMPOSITION
        protected virtual IMediaPlugin SelectMediaPlugin(PlaylistItem playlistItem)
        {
            IEnumerable<LooseMetadataLazy<IMediaPlugin, IMediaPluginMetadata>> results = PluginsManager.MediaPlugins
                .Where(
                    i =>
                    (playlistItem.DeliveryMethod == DeliveryMethods.NotSpecified ||
                        (i.Metadata.SupportedDeliveryMethods & playlistItem.DeliveryMethod) != DeliveryMethods.NotSpecified)
                        && playlistItem.MediaPluginRequiredMetadata.CompareMetadata(i.LooseMetadata));
            //If the media is live and we have implementations that support the live interface then
            //filter the list down to these implementations as they will provide
            //a better experience for the user, however, this is not a required to play the live media

            results = playlistItem.LiveDvrRequired && results.Any(i => i.Metadata.SupportsLiveDvr)
                            ? results.Where(i => i.Metadata.SupportsLiveDvr)
                            : results;

            //Favor Plugins that have already been instantiated
            LooseMetadataLazy<IMediaPlugin, IMediaPluginMetadata> result = results.Any(i => i.IsValueCreated)
                                                                                ? results.First(i => i.IsValueCreated)
                                                                                : results.FirstOrDefault();

            return result != null ? result.Value : null;
        }
Пример #20
0
        /// <summary>
        /// Converts this scriptable Playlist into playlist that can be consumed by the SMFPlayer.
        /// </summary>
        /// <returns>A collection of playlist items.</returns>
        public ObservableCollection<PlaylistItem> ToPlaylist()
        {
            var p = new ObservableCollection<PlaylistItem>();
            for (int i = 0; i < GetPlaylistItemCount(); i++)
            {
                ScriptPlaylistItem sItem = GetPlaylistItem(i);

                var thumbSource = !sItem.ThumbSource.IsNullOrWhiteSpace()
                                        ? new Uri(sItem.ThumbSource)
                                        : null;

                var item = new PlaylistItem
                               {
                                   DeliveryMethod =
                                       (DeliveryMethods)
                                       Enum.Parse(typeof (DeliveryMethods), sItem.DeliveryMethod, true),
                                   Description = sItem.Description,
                                   FileSize = sItem.FileSize,
                                   FrameRate = sItem.FrameRate,
                                   JumpToLive = sItem.JumpToLive,
                                   MediaSource = new Uri(sItem.MediaSource),
                                   ThumbSource = thumbSource,
                                   Title = sItem.Title,
                                   VideoHeight = sItem.VideoHeight,
                                   VideoStretchMode =
                                       (Stretch) Enum.Parse(typeof (Stretch), sItem.VideoStretchMode, true),
                                   VideoWidth = sItem.VideoWidth,
								   CustomMetadata = sItem.CustomMetadata,
								   S3DProperties = (sItem.ScriptS3DProperties == null) ? null : sItem.ScriptS3DProperties.ConvertToS3DProperties()
                               };
                for (int j = 0; j < sItem.MarkerCount; j++)
                {
                    ScriptMediaMarker smm = sItem.GetMarker(j);
                    
                    if(!smm.Type.IsNullOrWhiteSpace() && smm.Type.Equals("timeline", StringComparison.OrdinalIgnoreCase))
                    {
                        item.TimelineMarkers.Add(new TimelineMediaMarker
                                                     {
                                                         AllowSeek = smm.AllowSeek,
                                                         Begin = TimeSpan.FromSeconds(smm.Begin),
                                                         End = TimeSpan.FromSeconds(smm.End),
                                                         Id = smm.Id,
                                                         Content = smm.Content
                                                     });
                    }
                }
                for (int j = 0; j < sItem.ChapterCount; j++)
                {
                    ScriptChapter sci = sItem.GetChapter(j);
                    item.Chapters.Add(new Chapter
                                          {
                                              Begin = TimeSpan.FromSeconds(sci.Begin),
                                              End = TimeSpan.FromSeconds(sci.End),
                                              Id = sci.Id,
                                              Content = sci.Content,
                                              Description = sci.Description,
                                              Title = sci.Title,
                                              ThumbSource = new Uri(sci.ThumbSource),
                                              Type = "chapter"
                                          });
                }
                p.Add(item);
            }
            return p;
        }
 /// <summary>
 /// Goes to the specified playlist item.
 /// </summary>
 public void GoToPlaylistItem(PlaylistItem playlistItem)
 {
     if (Playlist != null && playlistItem != null && playlistItem != CurrentPlaylistItem &&
         Playlist.Contains(playlistItem))
     {
         CurrentPlaylistItem = playlistItem;
     }
 }
        private static void ConvertPlaylistItemToOffline(PlaylistItem playlistItem)
        {
            string offlineFilename;
            if (playlistItem.ThumbSource != null)
            {
                offlineFilename = playlistItem.ThumbSource.ComputeOfflineFilename();
                playlistItem.ThumbSource = new Uri(OfflineExtensions.IsolatedStorageUriPrefix + offlineFilename);
            }

            foreach (var chapter in playlistItem.Chapters)
            {
                if (chapter.ThumbSource != null)
                {
                    offlineFilename = chapter.ThumbSource.ComputeOfflineFilename();
                    chapter.ThumbSource = new Uri(OfflineExtensions.IsolatedStorageUriPrefix + offlineFilename);
                }
            }

            if (playlistItem.MarkerResources != null)
            {
                foreach (var r in playlistItem.MarkerResources)
                {
                    offlineFilename = r.Source.ComputeOfflineFilename();
                    r.Source = new Uri(OfflineExtensions.IsolatedStorageUriPrefix + offlineFilename);
                }
            }

            if (playlistItem.MediaSource != null)
            {
                offlineFilename = playlistItem.MediaSource.ComputeOfflineFilename();
                playlistItem.MediaSource = new Uri(OfflineExtensions.IsolatedStorageUriPrefix + offlineFilename);
            }
        }
        private static PlaylistItem ImportExpressionEncoderPlaylistItem(XElement element)
        {
            var item = new PlaylistItem
            {
                Description = HttpUtility.UrlDecode(element.Element("Description").GetValue(""))
            };
            long? fileSize = element.Element("Description").GetValueAsLong();
            if (fileSize != null) item.FileSize = fileSize.Value;
            double? frameRate = element.Element("FrameRate").GetValueAsDouble();
            if (frameRate != null) item.FrameRate = frameRate.Value;
            double? height = element.Element("Height").GetValueAsDouble();
            if (height != null) item.VideoHeight = height.Value;
            double? width = element.Element("Width").GetValueAsDouble();
            if (width != null) item.VideoWidth = width.Value;
            bool? isAdaptiveStreaming = element.Element("IsAdaptiveStreaming").GetValueAsBoolean();
            if (isAdaptiveStreaming != null && isAdaptiveStreaming == true)
            {
                item.DeliveryMethod = DeliveryMethods.AdaptiveStreaming;
            }
            else
            {
                string deliveryMethod = element.Element("DeliveryMethod").GetValue();
                if (deliveryMethod != null)
                    item.DeliveryMethod = Enum.IsDefined(typeof(DeliveryMethods), deliveryMethod) ? (DeliveryMethods)Enum.Parse(typeof(DeliveryMethods), deliveryMethod, true) : DeliveryMethods.NotSpecified;
            }
            string mediaSource = element.Element("MediaSource").GetValue();
            if (mediaSource != null)
            {
                mediaSource = HttpUtility.UrlDecode(mediaSource);
                if (mediaSource != null)
                {
                    if (mediaSource.ToLower().StartsWith("http:") ||
                    mediaSource.ToLower().StartsWith("https:"))
                    {
                        item.MediaSource = new Uri(mediaSource, UriKind.Absolute);
                    }
                    else
                    {
                        item.MediaSource = new Uri(mediaSource, UriKind.Relative);
                    }
                }
            }
            string thumbSource = element.Element("ThumbSource").GetValue();
            if (thumbSource != null)
            {
                thumbSource = HttpUtility.UrlDecode(thumbSource);
                if (thumbSource != null)
                {
                    if (thumbSource.ToLower().StartsWith("http:") ||
                    thumbSource.ToLower().StartsWith("https:"))
                    {
                        item.ThumbSource = new Uri(thumbSource, UriKind.Absolute);
                    }
                    else
                    {
                        item.ThumbSource = new Uri(thumbSource, UriKind.Relative);
                    }
                }
            }
            item.Title = HttpUtility.UrlDecode(element.Element("Title").GetValue(""));

            XElement s3DPropItems = element.Element("S3DProperties");
            if (s3DPropItems != null)
            {
                item.S3DProperties = ImportHTMLS3DProperties(s3DPropItems);
            }

            XElement customMetaDataItems = element.Element("CustomMetadata");
            if (customMetaDataItems != null)
            {
                item.CustomMetadata = ImportHTMLCustomMetaData(customMetaDataItems);
            }

            return item;
        }
 private void QueueOfflineTask(PlaylistItem playlistItem, Uri uri, OfflineTaskType taskType)
 {
     var task = new OfflineTask(playlistItem, taskType, uri);
     _pendingOfflineTasks[playlistItem].Add(task);
     AddRequest(task);
 }
        /// <summary>
        /// Load settings from init params
        /// </summary>
        /// <param name="initParams"></param>
        public void LoadInitParams(IDictionary<string, string> initParams)
        {
            bool autoPlay;
            FeatureVisibility playerGraphVisibility;

            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.Title))
            {
                MediaTitleContent = initParams.GetEntryIgnoreCase(SupportedInitParams.Title);
            }

            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.ScriptableName)
                && !initParams.GetEntryIgnoreCase(SupportedInitParams.ScriptableName).IsNullOrWhiteSpace())
            {
                ScriptableName = initParams.GetEntryIgnoreCase(SupportedInitParams.ScriptableName);
            }

            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.AutoPlay)
                && bool.TryParse(initParams.GetEntryIgnoreCase(SupportedInitParams.AutoPlay), out autoPlay))
            {
                AutoPlay = autoPlay;
            }

            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.PlayerGraphVisibility)
                && FeatureVisibility.TryParse(initParams.GetEntryIgnoreCase(SupportedInitParams.PlayerGraphVisibility), true, out playerGraphVisibility))
            {
                PlayerGraphVisibility = playerGraphVisibility;
            }

            bool isStartPositionOffset = true;
            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.IsStartPositionOffset) && bool.TryParse(initParams.GetEntryIgnoreCase(SupportedInitParams.IsStartPositionOffset), out isStartPositionOffset))
            {
                IsStartPositionOffset = isStartPositionOffset;
            }

            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.MediaUrl)
                && !initParams.GetEntryIgnoreCase(SupportedInitParams.MediaUrl).IsNullOrWhiteSpace())
            {
                var playlist = new ObservableCollection<PlaylistItem>();

                var playlistItem = new PlaylistItem
                {
                    MediaSource = new Uri(initParams.GetEntryIgnoreCase(SupportedInitParams.MediaUrl))
                };


                DeliveryMethods deliveryMethod;
                if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.DeliveryMethod)
                    && initParams.GetEntryIgnoreCase(SupportedInitParams.DeliveryMethod).EnumTryParse(true, out deliveryMethod))
                {
                    playlistItem.DeliveryMethod = deliveryMethod;
                }


                if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.SelectedCaptionStream)
                    && !initParams.GetEntryIgnoreCase(SupportedInitParams.SelectedCaptionStream).IsNullOrWhiteSpace())
                {
                    playlistItem.SelectedCaptionStreamName = initParams.GetEntryIgnoreCase(SupportedInitParams.SelectedCaptionStream);
                }

                if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.ThumbnailUrl)
                    && !initParams.GetEntryIgnoreCase(SupportedInitParams.ThumbnailUrl).IsNullOrWhiteSpace())
                {
                    playlistItem.ThumbSource = new Uri(initParams.GetEntryIgnoreCase(SupportedInitParams.ThumbnailUrl));
                }

                playlist.Add(playlistItem);
                Playlist = playlist;
            }
            else if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.PlayerSettings)
                && !initParams.GetEntryIgnoreCase(SupportedInitParams.PlayerSettings).IsNullOrWhiteSpace())
            {
                ImportPlayerSettings(initParams.GetEntryIgnoreCase(SupportedInitParams.PlayerSettings));
            }

            Uri pluginSource;
            if (initParams.ContainsKeyIgnoreCase(SupportedInitParams.PluginUrl)
                && !initParams.GetEntryIgnoreCase(SupportedInitParams.PluginUrl).IsNullOrWhiteSpace()
                && Uri.TryCreate(initParams.GetEntryIgnoreCase(SupportedInitParams.PluginUrl), UriKind.RelativeOrAbsolute, out pluginSource))
            {
                BeginAddExternalPlugins(pluginSource);
            }
        }