Ejemplo n.º 1
0
        public static void ReadItem(MediaItem item, XElement element)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            item.Description = (string)element.Attribute("description");
            item.Title = (string)element.Attribute("title");
            item.Thumbnail = (string)element.Attribute("thumbnail");
            item.Source = (string)element.Attribute("source");

            List<IMarkerSource> markerSources = new List<IMarkerSource>();
            foreach (var caption in element.Elements("captions").Elements("caption"))
            {
                var src = (string)caption.Attribute("source");
                var language = (string)caption.Attribute("language");
                Dictionary<string, object> metadata = new Dictionary<string, object>();

                if (!string.IsNullOrEmpty(language))
                {
                    metadata.Add(MarkerMetadata.Language, language);
                }

                Uri uriSrc;
                if (Uri.TryCreate(src, UriKind.RelativeOrAbsolute, out uriSrc))
                {
                    markerSources.Add(new WebClientMarkerSource { Source = uriSrc, Metadata = metadata });
                }
            }

            var chapters = element.Element("chapters");
            if (chapters != null)
            {
                MarkerSelector chapterSelector = new MarkerSelector();
                chapterSelector.Metadata.Add(MarkerMetadata.Chapter, string.Empty);
                foreach (var chapter in chapters.Elements("chapter"))
                {
                    MarkerThumbnail marker = new MarkerThumbnail();
                    var start = (TimeSpan?)chapter.Attribute("start");
                    if (start.HasValue)
                    {
                        marker.Position = start.Value;
                        chapterSelector.Markers.Add(marker);
                    }
                    marker.Content = (string)chapter.Attribute("title");
                    var thumb = (string)chapter.Attribute("thumbnail");
                    Uri uriThumbnail;
                    if (!string.IsNullOrEmpty(thumb) && Uri.TryCreate(thumb, UriKind.RelativeOrAbsolute, out uriThumbnail))
                        marker.Thumbnail = uriThumbnail;
                }
                item.MarkerSelectors.Add(chapterSelector);
            }

            item.MarkerSources = markerSources.ToArray();
        }
Ejemplo n.º 2
0
        void player_Loaded(object sender, RoutedEventArgs e)
        {
            if (mediaController != null)
            {
                if (!string.IsNullOrEmpty(provider))
                {
                    switch (provider.ToLower())
                    {
                        case "mediarss":
                            {
                                MediaRssProvider rssProvider = new MediaRssProvider();
                                string url;
                                Uri uri;
                                if (initParams.TryGetValue("url", out url)
                                    && Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out uri))
                                {
                                    rssProvider.ContentSource = uri;
                                    mediaController.PlaylistSource = rssProvider;
                                }
                            }
                            break;
                        case "msnvideo":
                            {
                                MSNVideoProvider msnProvider = new MSNVideoProvider();
                                string url;
                                Uri uri;
                                if (initParams.TryGetValue("url", out url) && Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out uri))
                                {
                                    msnProvider.ContentSource = uri;
                                    mediaController.PlaylistSource = msnProvider;
                                }
                            }
                            break;
                        default:
                            break;
                    }
                }
                else
                {

                    foreach (var source in sources)
                    {
                        SLMedia.Core.MediaItem item = new SLMedia.Core.MediaItem();
                        item.Source = source;
                        mediaController.Playlist.Add(item);
                        mediaController.CurrentItem = item;
                    }

                    //if (mediaController is DeepZoomController)
                    //{

                    //}
                    //else
                    //{
                    //}
                }
            }
        }