public async Task <bool> LoadPlaylist()
        {
            IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>();
            IContentDirectory        cd  = scm.ContentDirectory;

            if (cd == null)
            {
                ShowServerNotConnectedDialog();
                return(false);
            }
            // Big playlists cannot be loaded in one single step. We have several problems if we try to do so:
            // 1) Loading the playlist at once at the server results in one huge SQL IN statement which might break the SQL engine
            // 2) The time to load the playlist might lead the UPnP call to break because of the timeout when calling methods
            // 3) The resulting UPnP XML document might be too big to fit into memory

            // For that reason, we load the playlist in two steps:
            // 1) Load media item ids in the playlist
            // 2) Load media items in clusters - for each cluster, an own query will be executed at the content directory
            PlaylistRawData playlistData = await cd.ExportPlaylistAsync(_playlistId);

            List <MediaItem> result = new List <MediaItem>();

            foreach (IList <Guid> itemIds in CollectionUtils.Cluster(playlistData.MediaItemIds, 500))
            {
                result.AddRange(await cd.LoadCustomPlaylistAsync(itemIds, Consts.NECESSARY_AUDIO_MIAS, Consts.EMPTY_GUID_ENUMERATION));
            }
            _mediaItems = result;
            return(true);
        }
Пример #2
0
        internal static async Task <(string Name, IEnumerable <MediaItem> Items)> LoadPlayListAsync(Guid playlistId)
        {
            IContentDirectory cd = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory;

            Guid[] necessaryMIATypes = new Guid[]
            {
                ProviderResourceAspect.ASPECT_ID,
                MediaAspect.ASPECT_ID,
            };
            Guid[] optionalMIATypes = new Guid[]
            {
                AudioAspect.ASPECT_ID,
                VideoAspect.ASPECT_ID,
                ImageAspect.ASPECT_ID,
                MovieAspect.ASPECT_ID,
                EpisodeAspect.ASPECT_ID,
                GenreAspect.ASPECT_ID,
                VideoStreamAspect.ASPECT_ID,
            };

            PlaylistRawData playlistData = await cd.ExportPlaylistAsync(playlistId);

            List <MediaItem> items = new List <MediaItem>();

            foreach (var cluster in CollectionUtils.Cluster(playlistData.MediaItemIds, 1000))
            {
                items.AddRange(await cd.LoadCustomPlaylistAsync(cluster, necessaryMIATypes, optionalMIATypes));
            }
            return(playlistData.Name, items);
        }
        public async Task <bool> LoadPlaylist()
        {
            IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>();
            IContentDirectory        cd  = scm.ContentDirectory;

            if (cd == null)
            {
                ShowServerNotConnectedDialog();
                return(false);
            }
            PlaylistRawData playlistData = await cd.ExportPlaylistAsync(_playlistId);

            _mediaItems = await cd.LoadCustomPlaylistAsync(playlistData.MediaItemIds, Consts.NECESSARY_AUDIO_MIAS, Consts.EMPTY_GUID_ENUMERATION);

            return(true);
        }
Пример #4
0
        public async Task LoadPlaylist()
        {
            IDialogManager dialogManager = ServiceRegistration.Get <IDialogManager>();

            if (_playlist == null)
            {
                dialogManager.ShowDialog(SkinBase.General.Consts.RES_SYSTEM_ERROR, Consts.RES_PLAYLIST_LOAD_NO_PLAYLIST, DialogType.OkDialog, false, null);
                return;
            }
            IContentDirectory cd     = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory;
            AVType?           avType = ConvertPlaylistTypeToAVType(_playlist.PlaylistType);

            if (cd == null || !avType.HasValue)
            {
                dialogManager.ShowDialog(SkinBase.General.Consts.RES_SYSTEM_ERROR, Consts.RES_PLAYLIST_LOAD_ERROR_LOADING, DialogType.OkDialog, false, null);
                return;
            }
            Guid[] necessaryMIATypes = new Guid[]
            {
                ProviderResourceAspect.ASPECT_ID,
                MediaAspect.ASPECT_ID,
            };
            Guid[] optionalMIATypes = new Guid[]
            {
                AudioAspect.ASPECT_ID,
                VideoAspect.ASPECT_ID,
                ImageAspect.ASPECT_ID,
            };
            // Big playlists cannot be loaded in one single step. We have several problems if we try to do so:
            // 1) Loading the playlist at once at the server results in one huge SQL IN statement which might break the SQL engine
            // 2) The time to load the playlist might lead the UPnP call to break because of the timeout when calling methods
            // 3) The resulting UPnP XML document might be too big to fit into memory

            // For that reason, we load the playlist in two steps:
            // 1) Load media item ids in the playlist
            // 2) Load media items in clusters - for each cluster, an own query will be executed at the content directory
            PlaylistRawData playlistData = await cd.ExportPlaylistAsync(_playlist.PlaylistId);

            PlayItemsModel.CheckQueryPlayAction(() => CollectionUtils.Cluster(playlistData.MediaItemIds, 1000).SelectMany(itemIds =>
                                                                                                                          cd.LoadCustomPlaylistAsync(itemIds, necessaryMIATypes, optionalMIATypes).Result), avType.Value);
        }