protected static string GetFanArtName(ListItem listItem) { PlayableMediaItem playableMediaItem = listItem as PlayableMediaItem; if (playableMediaItem != null) { if (playableMediaItem.MediaItem != null) { // Fanart loading now depends on the MediaItemId to support local fanart return(playableMediaItem.MediaItem.MediaItemId.ToString()); } return(string.Empty); } FilterItem filterItem = listItem as FilterItem; if (filterItem != null) { if (filterItem.MediaItem != null) { // Fanart loading now depends on the MediaItemId to support local fanart return(filterItem.MediaItem.MediaItemId.ToString()); } return(string.Empty); } return(string.Empty); }
protected void UpdatePlaylist() { IPlayerContextManager playerContextManager = ServiceRegistration.Get <IPlayerContextManager>(); IPlayerContext pc = playerContextManager.GetPlayerContext(PlayerChoice.CurrentPlayer); IPlaylist playlist = pc == null ? null : pc.Playlist; UpdatePlaylistHeader(pc == null ? null : (AVType?)pc.AVType, pc == null ? true : pc.IsPrimaryPlayerContext); lock (_syncObj) { _playlist = playlist; _playlistItems.Clear(); if (playlist != null) { int ct = 0; int currentItemIdx = playlist.ItemListIndex; foreach (MediaItem mediaItem in playlist.ItemList) { int idx = ct++; PlayableMediaItem item = PlayableMediaItem.CreateItem(mediaItem); item.SetLabel(Consts.KEY_NUMBERSTR, (idx + 1) + "."); item.AdditionalProperties[Consts.KEY_INDEX] = idx; item.AdditionalProperties[Consts.KEY_IS_CURRENT_ITEM] = currentItemIdx == idx; _playlistItems.Add(item); } } IsPlaylistEmpty = _playlistItems.Count == 0; NumPlaylistItemsStr = Utils.BuildNumItemsStr(_playlistItems.Count, null); } _playlistItems.FireChange(); }
private void SetFanArtType() { PlayableMediaItem playableMediaItem = SelectedItem as PlayableMediaItem; if (playableMediaItem != null) { MediaItem = playableMediaItem.MediaItem; } SeriesFilterItem series = SelectedItem as SeriesFilterItem; if (series != null) { FanArtMediaType = FanArtConstants.FanArtMediaType.Series; FanArtName = series.SimpleTitle; ItemDescription = null; return; } SeriesItem episode = SelectedItem as SeriesItem; if (episode != null) { FanArtMediaType = FanArtConstants.FanArtMediaType.Series; FanArtName = episode.Series; ItemDescription = episode.StoryPlot; return; } MovieFilterItem movieCollection = SelectedItem as MovieFilterItem; if (movieCollection != null) { FanArtMediaType = FanArtConstants.FanArtMediaType.MovieCollection; FanArtName = movieCollection.SimpleTitle; ItemDescription = null; return; } MovieItem movie = SelectedItem as MovieItem; if (movie != null) { FanArtMediaType = FanArtConstants.FanArtMediaType.Movie; // Fanart loading now depends on the MediaItemId to support local fanart FanArtName = movie.MediaItem.MediaItemId.ToString(); ItemDescription = movie.StoryPlot; return; } VideoItem video = SelectedItem as VideoItem; if (video != null) { FanArtMediaType = FanArtConstants.FanArtMediaType.Movie; // Fanart loading now depends on the MediaItemId to support local fanart FanArtName = video.MediaItem.MediaItemId.ToString(); ItemDescription = video.StoryPlot; return; } FanArtMediaType = FanArtConstants.FanArtMediaType.Undefined; FanArtName = string.Empty; ItemDescription = string.Empty; }
protected static async Task FillListAsync(IContentDirectory contentDirectory, Guid[] necessaryMIATypeIds, ItemsList list, MediaItemToListItemAction converterAction) { MediaItemQuery query = new MediaItemQuery(necessaryMIATypeIds, null) { Limit = QUERY_LIMIT, // Last 5 imported items SortInformation = new List <ISortInformation> { new AttributeSortInformation(ImporterAspect.ATTR_DATEADDED, SortDirection.Descending) } }; Guid? userProfile = null; IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>(); if (userProfileDataManagement != null && userProfileDataManagement.IsValidUser) { userProfile = userProfileDataManagement.CurrentUser.ProfileId; } bool showVirtual = VirtualMediaHelper.ShowVirtualMedia(necessaryMIATypeIds); var items = await contentDirectory.SearchAsync(query, false, userProfile, showVirtual); list.Clear(); foreach (MediaItem mediaItem in items) { PlayableMediaItem listItem = converterAction(mediaItem); listItem.Command = new MethodDelegateCommand(() => PlayItemsModel.CheckQueryPlayAction(listItem.MediaItem)); list.Add(listItem); } list.FireChange(); }
static void Main(string[] args) { MediaLibrary library = new MediaLibrary(); library.MediaItems.Add(new Movie("Jaws", "Spielberg")); library.MediaItems.Add(new Song("Shreveport Stomp", "Jelly-Roll Morton")); library.MediaItems.Add(new Picture("The Royal Family", "David Bailey")); library.MediaItems.Add(new RadioShow("I'm sorry I'll read that again", "John Cleese")); foreach (MediaItem mi in library.MediaItems) { // TODO 1 use the dollar style of string.Format to Console.WriteLine : Title, MainPerson and MainPersonRole Console.WriteLine($"{mi.Title}, the {mi.MainPersonRole} is {mi.MainPerson}"); PlayableMediaItem pmi = mi as PlayableMediaItem; // TODO 2 use the Elvis operator to call IsAuthorized, Play(), Pause() and Stop() if (pmi?.IsAuthorized == true) { pmi?.Play(); pmi?.Pause(); pmi?.Stop(); } Console.WriteLine(); } }
protected void UpdatePlaylist() { IPlayerContextManager playerContextManager = ServiceRegistration.Get <IPlayerContextManager>(); IPlayerContext pc = playerContextManager.GetPlayerContext(PlayerChoice.CurrentPlayer); IPlaylist playlist = pc == null ? null : pc.Playlist; UpdatePlaylistHeader(pc == null ? null : (AVType?)pc.AVType, pc == null ? true : pc.IsPrimaryPlayerContext); lock (_syncObj) { // TODO: If playlist objects differ, leave state EditPlaylist? _playlist = playlist; _items.Clear(); if (playlist != null) { IList <MediaItem> items = playlist.ItemList; for (int i = 0; i < items.Count; i++) { MediaItem mediaItem = items[i]; PlayableMediaItem item = PlayableMediaItem.CreateItem(mediaItem); item.SetLabel(Consts.KEY_NUMBERSTR, (i + 1) + "."); item.AdditionalProperties[Consts.KEY_INDEX] = i; item.AdditionalProperties[Consts.KEY_IS_DOWN_BUTTON_FOCUSED] = i == _focusedDownButton; item.AdditionalProperties[Consts.KEY_IS_UP_BUTTON_FOCUSED] = i == _focusedUpButton; _items.Add(item); } } _focusedDownButton = -1; _focusedUpButton = -1; IsPlaylistEmpty = _items.Count == 0; NumPlaylistItemsStr = Utils.BuildNumItemsStr(_items.Count, null); } _items.FireChange(); }
protected void FillList(IContentDirectory contentDirectory, Guid[] necessaryMIAs, ItemsList list, MediaItemToListItemAction converterAction) { MediaItemQuery query = new MediaItemQuery(necessaryMIAs, null) { Limit = (uint)QueryLimit, // Last 5 imported items SortInformation = new List <SortInformation> { new SortInformation(ImporterAspect.ATTR_DATEADDED, SortDirection.Descending) } }; Guid? userProfile = null; IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>(); if (userProfileDataManagement != null && userProfileDataManagement.IsValidUser) { userProfile = userProfileDataManagement.CurrentUser.ProfileId; } var items = contentDirectory.Search(query, false, userProfile, false); list.Clear(); foreach (MediaItem mediaItem in items) { PlayableMediaItem listItem = converterAction(mediaItem); listItem.Command = new MethodDelegateCommand(() => PlayItemsModel.CheckQueryPlayAction(listItem.MediaItem)); list.Add(listItem); } list.FireChange(); }
public void SortByRecordingDate(ItemsList items, Sorting sorting) { var sorted = items.ToList(); sorted.Sort((item1, item2) => { PlayableMediaItem pmi1 = item1 as PlayableMediaItem; ViewItem vi1 = item1 as ViewItem; PlayableMediaItem pmi2 = item2 as PlayableMediaItem; ViewItem vi2 = item2 as ViewItem; MediaItem mi1 = pmi1 != null ? pmi1.MediaItem : (vi1 != null ? vi1.FirstMediaItem : null); MediaItem mi2 = pmi2 != null ? pmi2.MediaItem : (vi2 != null ? vi2.FirstMediaItem : null); return(sorting.Compare(mi1, mi2)); }); items.Clear(); CollectionUtils.AddAll(items, sorted); }
protected static void FillList(IContentDirectory contentDirectory, Guid[] necessaryMIAs, ItemsList list, MediaItemToListItemAction converterAction) { MediaItemQuery query = new MediaItemQuery(necessaryMIAs, null) { Limit = QUERY_LIMIT, // Last 5 imported items SortInformation = new List<SortInformation> { new SortInformation(ImporterAspect.ATTR_DATEADDED, SortDirection.Descending) } }; var items = contentDirectory.Search(query, false); list.Clear(); foreach (MediaItem mediaItem in items) { PlayableMediaItem listItem = converterAction(mediaItem); listItem.Command = new MethodDelegateCommand(() => PlayItemsModel.CheckQueryPlayAction(listItem.MediaItem)); list.Add(listItem); } list.FireChange(); }
protected void UpdateLoadedMediaItems(MediaItem mediaItem, ContentDirectoryMessaging.MediaItemChangeType changeType) { if (changeType == ContentDirectoryMessaging.MediaItemChangeType.None) { return; } bool changed = false; lock (_syncObj) { if (changeType == ContentDirectoryMessaging.MediaItemChangeType.Deleted) { PlayableMediaItem existingItem = _items.OfType <PlayableMediaItem>().FirstOrDefault(pmi => pmi.MediaItem.Equals(mediaItem)); if (existingItem != null) { int oldIndex = _items.IndexOf(existingItem); _items.Remove(existingItem); // Restore focus on same position of old item SetSelectedIndex(oldIndex); _currentTotalNumItems--; changed = true; } } if (changeType == ContentDirectoryMessaging.MediaItemChangeType.Updated) { IEnumerable <PlayableMediaItem> playableItems = _items.OfType <PlayableMediaItem>(); PlayableMediaItem existingItem = playableItems.FirstOrDefault(pmi => pmi.MediaItem.Equals(mediaItem)); if (existingItem != null) { existingItem.Update(mediaItem); changed = SetSelectedItem(playableItems); } } } if (changed) { _items.FireChange(); Display_Normal(_items.Count, _currentTotalNumItems); } }
protected void UpdateLoadedMediaItems(MediaItem mediaItem, ContentDirectoryMessaging.MediaItemChangeType changeType) { if (changeType == ContentDirectoryMessaging.MediaItemChangeType.None) { return; } bool changed = false; lock (_syncObj) { if (changeType == ContentDirectoryMessaging.MediaItemChangeType.Deleted) { PlayableMediaItem existingItem = _items.OfType <PlayableMediaItem>().FirstOrDefault(pmi => pmi.MediaItem.Equals(mediaItem)); if (existingItem != null) { _items.Remove(existingItem); _currentTotalNumItems--; changed = true; } } if (changeType == ContentDirectoryMessaging.MediaItemChangeType.Updated) { PlayableMediaItem existingItem = _items.OfType <PlayableMediaItem>().FirstOrDefault(pmi => pmi.MediaItem.Equals(mediaItem)); if (existingItem != null) { existingItem.Update(mediaItem); } } } if (changed) { _items.FireChange(); Display_Normal(_items.Count, _currentTotalNumItems); } }
private void SetFanArtType() { // Applies only to container Items NumItems = null; PlayableMediaItem playableMediaItem = SelectedItem as PlayableMediaItem; if (playableMediaItem != null) { MediaItem = playableMediaItem.MediaItem; SimpleTitle = playableMediaItem.SimpleTitle; } else { MediaItem = null; SimpleTitle = string.Empty; } SeriesFilterItem series = SelectedItem as SeriesFilterItem; if (series != null) { MediaItem = series.MediaItem; SimpleTitle = series.SimpleTitle; ItemDescription = series.StoryPlot; return; } SeasonFilterItem season = SelectedItem as SeasonFilterItem; if (season != null) { MediaItem = season.MediaItem; SimpleTitle = season.SimpleTitle; ItemDescription = season.StoryPlot; return; } EpisodeItem episode = SelectedItem as EpisodeItem; if (episode != null) { MediaItem = episode.MediaItem; SimpleTitle = episode.Series; ItemDescription = episode.StoryPlot; return; } MovieFilterItem movieCollection = SelectedItem as MovieFilterItem; if (movieCollection != null) { MediaItem = movieCollection.MediaItem; SimpleTitle = movieCollection.SimpleTitle; ItemDescription = null; return; } MovieItem movie = SelectedItem as MovieItem; if (movie != null) { MediaItem = movie.MediaItem; SimpleTitle = movie.SimpleTitle; ItemDescription = movie.StoryPlot; return; } VideoItem video = SelectedItem as VideoItem; if (video != null) { MediaItem = video.MediaItem; SimpleTitle = video.SimpleTitle; ItemDescription = video.StoryPlot; return; } AlbumFilterItem albumItem = SelectedItem as AlbumFilterItem; if (albumItem != null) { MediaItem = albumItem.MediaItem; SimpleTitle = albumItem.SimpleTitle; ItemDescription = albumItem.Description; return; } AudioItem audioItem = SelectedItem as AudioItem; if (audioItem != null) { MediaItem = audioItem.MediaItem; SimpleTitle = audioItem.SimpleTitle; ItemDescription = string.Empty; return; } ActorFilterItem actorItem = SelectedItem as ActorFilterItem; if (actorItem != null) { MediaItem = actorItem.MediaItem; SimpleTitle = actorItem.SimpleTitle; ItemDescription = actorItem.Description; return; } DirectorFilterItem directorItem = SelectedItem as DirectorFilterItem; if (directorItem != null) { MediaItem = directorItem.MediaItem; SimpleTitle = directorItem.SimpleTitle; ItemDescription = directorItem.Description; } WriterFilterItem writerItem = SelectedItem as WriterFilterItem; if (writerItem != null) { MediaItem = writerItem.MediaItem; SimpleTitle = writerItem.SimpleTitle; ItemDescription = writerItem.Description; } ArtistFilterItem artisitItem = SelectedItem as ArtistFilterItem; if (artisitItem != null) { MediaItem = artisitItem.MediaItem; SimpleTitle = artisitItem.SimpleTitle; ItemDescription = artisitItem.Description; } ComposerFilterItem composerItem = SelectedItem as ComposerFilterItem; if (composerItem != null) { MediaItem = composerItem.MediaItem; SimpleTitle = composerItem.SimpleTitle; ItemDescription = composerItem.Description; } CharacterFilterItem characterItem = SelectedItem as CharacterFilterItem; if (characterItem != null) { MediaItem = characterItem.MediaItem; SimpleTitle = characterItem.SimpleTitle; ItemDescription = string.Empty; } CompanyFilterItem companyItem = SelectedItem as CompanyFilterItem; if (companyItem != null) { MediaItem = companyItem.MediaItem; SimpleTitle = companyItem.SimpleTitle; ItemDescription = companyItem.Description; } TVNetworkFilterItem tvNetworkItem = SelectedItem as TVNetworkFilterItem; if (tvNetworkItem != null) { MediaItem = tvNetworkItem.MediaItem; SimpleTitle = tvNetworkItem.SimpleTitle; ItemDescription = tvNetworkItem.Description; } FilterItem filterItem = SelectedItem as FilterItem; if (filterItem != null) { MediaItem = filterItem.MediaItem; SimpleTitle = filterItem.SimpleTitle; ItemDescription = string.Empty; NumItems = filterItem.NumItems; return; } ContainerItem containerItem = SelectedItem as ContainerItem; if (containerItem != null) { // Morpheus 2017-04-27: setting the media item for containers lead to unintended layout in views // MediaItem = containerItem.FirstMediaItem; MediaItem = null; if (Guid.TryParse(containerItem.Id, out Guid dirId)) { MediaItem = new MediaItem(dirId); } SimpleTitle = containerItem.SimpleTitle; ItemDescription = string.Empty; NumItems = containerItem.NumItems; return; } FanArtMediaType = FanArtMediaTypes.Undefined; FanArtName = string.Empty; ItemDescription = string.Empty; }
public virtual async Task <bool> UpdateItemsAsync(int maxItems, UpdateReason updateReason) { if (!ShouldUpdate(updateReason)) { return(false); } if (_playableConverterAction == null && _playableContainerConverterAction == null) { return(false); } var contentDirectory = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory; if (contentDirectory == null) { return(false); } MediaItemQuery query = await CreateQueryAsync(); if (query == null) { return(false); } query.Limit = (uint)maxItems; Guid?userProfile = CurrentUserProfile?.ProfileId; bool showVirtual = VirtualMediaHelper.ShowVirtualMedia(_necessaryMias); var items = await contentDirectory.SearchAsync(query, true, userProfile, showVirtual); lock (_allItems.SyncRoot) { if (_currentMediaItems != null && _currentMediaItems.Select(m => m.MediaItemId).SequenceEqual(items.Select(m => m.MediaItemId))) { return(false); } _currentMediaItems = items; IEnumerable <ListItem> listItems; if (_playableConverterAction != null) { listItems = items.Select(mi => { PlayableMediaItem listItem = _playableConverterAction(mi); listItem.Command = new MethodDelegateCommand(() => PlayItemsModel.CheckQueryPlayAction(listItem.MediaItem)); return(listItem); }); } else { listItems = items.Select(mi => _playableContainerConverterAction(mi)); } _allItems.Clear(); CollectionUtils.AddAll(_allItems, listItems); } _allItems.FireChange(); return(true); }
private void Update() { PlayableMediaItem playableMediaItem = SelectedItem as PlayableMediaItem; if (playableMediaItem != null) { MediaItem = playableMediaItem.MediaItem; SimpleTitle = playableMediaItem.SimpleTitle; } else { MediaItem = null; SimpleTitle = string.Empty; } SeriesFilterItem series = SelectedItem as SeriesFilterItem; if (series != null) { SimpleTitle = series.SimpleTitle; ItemDescription = null; return; } SeriesItem episode = SelectedItem as SeriesItem; if (episode != null) { SimpleTitle = episode.Series; ItemDescription = episode.StoryPlot; return; } MovieFilterItem movieCollection = SelectedItem as MovieFilterItem; if (movieCollection != null) { SimpleTitle = movieCollection.SimpleTitle; ItemDescription = null; return; } MovieItem movie = SelectedItem as MovieItem; if (movie != null) { SimpleTitle = movie.SimpleTitle; ItemDescription = movie.StoryPlot; return; } VideoItem video = SelectedItem as VideoItem; if (video != null) { SimpleTitle = video.SimpleTitle; ItemDescription = video.StoryPlot; return; } FilterItem filterItem = SelectedItem as FilterItem; if (filterItem != null) { SimpleTitle = filterItem.SimpleTitle; ItemDescription = string.Empty; return; } ItemDescription = string.Empty; }