Exemplo n.º 1
0
        public static PlayableItem GetCurrentPlaybackItemUsingMetadataTitle(PlaybackController controllerInstance, IEnumerable <PlayableItem> playableItems, string metadataTitle, out int filePlaylistPosition, out int currentMediaIndex)
        {
            filePlaylistPosition = -1;
            currentMediaIndex    = -1;

            metadataTitle = metadataTitle.ToLower();

            // Loop through each PlayableItem and try to find a match
            foreach (PlayableItem playable in playableItems)
            {
                if (playable.HasMediaItems)
                {
                    // The PlayableItem has Media items, so loop through each one and look for a match

                    int totalFileCount = 0;
                    int numMediaItems  = playable.MediaItems.Count();

                    for (int i = 0; i < numMediaItems; i++)
                    {
                        Media media = playable.MediaItems.ElementAt(i);

                        IEnumerable <string> files = controllerInstance.GetPlayableFiles(media);

                        int index = PlaybackControllerHelper.GetIndexOfFileInPlaylist(files, metadataTitle);

                        if (index != -1)
                        {
                            filePlaylistPosition = index + totalFileCount;
                            currentMediaIndex    = i;
                            return(playable);
                        }

                        totalFileCount += files.Count();
                    }
                }
                else
                {
                    // There are no Media items so just find the index using the Files property
                    int index = PlaybackControllerHelper.GetIndexOfFileInPlaylist(playable.FilesFormattedForPlayer, metadataTitle);

                    if (index != -1)
                    {
                        filePlaylistPosition = index;
                        return(playable);
                    }
                }
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Then playback is based on Media items, this will populate the MediaCollection using the items
        /// </summary>
        public static void PopulateMediaCollectionUsingMediaItems(PlaybackController controllerInstance, MediaCollection coll, PlayableItem playable)
        {
            int currentFileIndex = 0;
            int collectionIndex  = coll.Count;
            int numItems         = playable.MediaItems.Count();

            for (int mediaIndex = 0; mediaIndex < numItems; mediaIndex++)
            {
                Media media = playable.MediaItems.ElementAt(mediaIndex);

                IEnumerable <string> files = controllerInstance.GetPlayableFiles(media);

                int numFiles = files.Count();

                // Create a MediaCollectionItem for each file to play
                for (int i = 0; i < numFiles; i++)
                {
                    string path = files.ElementAt(i);

                    Dictionary <string, object> friendlyData = new Dictionary <string, object>();

                    // Embed the playlist index, since we could have multiple playlists queued up
                    // which prevents us from being able to use MediaCollection.CurrentIndex
                    friendlyData["FilePlaylistPosition"] = currentFileIndex.ToString();

                    // Embed the PlayableItemId so we can identify which one to track progress for
                    friendlyData["PlayableItemId"] = playable.Id.ToString();

                    // Embed the Media index so we can identify which one to track progress for
                    friendlyData["MediaIndex"] = mediaIndex.ToString();

                    // Set a friendly title
                    friendlyData["Title"] = media.Name;

                    coll.AddItem(path, collectionIndex, -1, string.Empty, friendlyData);

                    currentFileIndex++;
                    collectionIndex++;
                }
            }
        }
        /// <summary>
        /// Then playback is based on Media items, this will populate the MediaCollection using the items
        /// </summary>
        public static void PopulateMediaCollectionUsingMediaItems(PlaybackController controllerInstance, MediaCollection coll, PlayableItem playable)
        {
            int currentFileIndex = 0;
            int collectionIndex = coll.Count;
            int numItems = playable.MediaItems.Count();

            for (int mediaIndex = 0; mediaIndex < numItems; mediaIndex++)
            {
                Media media = playable.MediaItems.ElementAt(mediaIndex);

                IEnumerable<string> files = controllerInstance.GetPlayableFiles(media);

                int numFiles = files.Count();

                // Create a MediaCollectionItem for each file to play
                for (int i = 0; i < numFiles; i++)
                {
                    string path = files.ElementAt(i);

                    Dictionary<string, object> friendlyData = new Dictionary<string, object>();

                    // Embed the playlist index, since we could have multiple playlists queued up
                    // which prevents us from being able to use MediaCollection.CurrentIndex
                    friendlyData["FilePlaylistPosition"] = currentFileIndex.ToString();

                    // Embed the PlayableItemId so we can identify which one to track progress for
                    friendlyData["PlayableItemId"] = playable.Id.ToString();

                    // Embed the Media index so we can identify which one to track progress for
                    friendlyData["MediaIndex"] = mediaIndex.ToString();

                    // Set a friendly title
                    friendlyData["Title"] = media.Name;

                    coll.AddItem(path, collectionIndex, -1, string.Empty, friendlyData);

                    currentFileIndex++;
                    collectionIndex++;
                }
            }
        }
        public static PlayableItem GetCurrentPlaybackItemUsingMetadataTitle(PlaybackController controllerInstance, IEnumerable<PlayableItem> playableItems, string metadataTitle, out int filePlaylistPosition, out int currentMediaIndex)
        {
            filePlaylistPosition = -1;
            currentMediaIndex = -1;

            metadataTitle = metadataTitle.ToLower();

            // Loop through each PlayableItem and try to find a match
            foreach (PlayableItem playable in playableItems)
            {
                if (playable.HasMediaItems)
                {
                    // The PlayableItem has Media items, so loop through each one and look for a match

                    int totalFileCount = 0;
                    int numMediaItems = playable.MediaItems.Count();

                    for (int i = 0; i < numMediaItems; i++)
                    {
                        Media media = playable.MediaItems.ElementAt(i);

                        IEnumerable<string> files = controllerInstance.GetPlayableFiles(media);

                        int index = PlaybackControllerHelper.GetIndexOfFileInPlaylist(files, metadataTitle);

                        if (index != -1)
                        {
                            filePlaylistPosition = index + totalFileCount;
                            currentMediaIndex = i;
                            return playable;
                        }

                        totalFileCount += files.Count();
                    }
                }
                else
                {
                    // There are no Media items so just find the index using the Files property
                    int index = PlaybackControllerHelper.GetIndexOfFileInPlaylist(playable.FilesFormattedForPlayer, metadataTitle);

                    if (index != -1)
                    {
                        filePlaylistPosition = index;
                        return playable;
                    }
                }
            }

            return null;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Then playback is based on Media items, this will populate the MediaCollection using the items
        /// </summary>
        public static void PopulateMediaCollectionUsingMediaItems(PlaybackController controllerInstance, MediaCollection coll, PlayableItem playable)
        {
            int currentFileIndex = 0;
            int collectionIndex  = coll.Count;
            int numItems         = playable.MediaItems.Count();

            for (int mediaIndex = 0; mediaIndex < numItems; mediaIndex++)
            {
                Media media = playable.MediaItems.ElementAt(mediaIndex);

                IEnumerable <string> files = controllerInstance.GetPlayableFiles(media);

                int numFiles = files.Count();

                // Create a MediaCollectionItem for each file to play
                for (int i = 0; i < numFiles; i++)
                {
                    string path = files.ElementAt(i);

                    Dictionary <string, object> friendlyData = new Dictionary <string, object>();

                    // Embed the playlist index, since we could have multiple playlists queued up
                    // which prevents us from being able to use MediaCollection.CurrentIndex
                    friendlyData["FilePlaylistPosition"] = currentFileIndex.ToString();

                    // Embed the PlayableItemId so we can identify which one to track progress for
                    friendlyData["PlayableItemId"] = playable.Id.ToString();

                    // Embed the Media index so we can identify which one to track progress for
                    friendlyData["MediaIndex"] = mediaIndex.ToString();

                    // Set a friendly title
                    friendlyData["Title"] = media.Name;

                    var song = media as Song;

                    if (song != null)
                    {
                        var itemImage = song.PrimaryImagePath;

                        // The following "friendly" data fields are undocumented but working for song items...
                        if (playable.Folder != null)
                        {
                            // This is either a music album or a playlist
                            friendlyData["AlbumTitle"] = playable.Folder.Name;
                            if (string.IsNullOrEmpty(itemImage))
                            {
                                itemImage = playable.Folder.PrimaryImagePath;
                            }
                        }
                        else
                        {
                            friendlyData["AlbumTitle"] = song.Album;
                        }

                        friendlyData["AlbumArtist"] = song.AlbumArtist;
                        friendlyData["Artist"]      = song.Artist;
                        friendlyData["TrackNumber"] = currentFileIndex;

                        if (song.PremierDate != DateTime.MinValue)
                        {
                            friendlyData["YearReleased"] = song.PremierDate.Year;
                        }

                        if (!string.IsNullOrEmpty(itemImage))
                        {
                            friendlyData["AlbumCoverUrl"] = itemImage;
                        }
                    }

                    coll.AddItem(path, collectionIndex, -1, string.Empty, friendlyData);

                    currentFileIndex++;
                    collectionIndex++;
                }
            }
        }
        /// <summary>
        /// Then playback is based on Media items, this will populate the MediaCollection using the items
        /// </summary>
        public static void PopulateMediaCollectionUsingMediaItems(PlaybackController controllerInstance, MediaCollection coll, PlayableItem playable)
        {
            int currentFileIndex = 0;
            int collectionIndex = coll.Count;
            int numItems = playable.MediaItems.Count();

            for (int mediaIndex = 0; mediaIndex < numItems; mediaIndex++)
            {
                Media media = playable.MediaItems.ElementAt(mediaIndex);

                IEnumerable<string> files = controllerInstance.GetPlayableFiles(media);

                int numFiles = files.Count();

                // Create a MediaCollectionItem for each file to play
                for (int i = 0; i < numFiles; i++)
                {
                    string path = files.ElementAt(i);

                    Dictionary<string, object> friendlyData = new Dictionary<string, object>();

                    // Embed the playlist index, since we could have multiple playlists queued up
                    // which prevents us from being able to use MediaCollection.CurrentIndex
                    friendlyData["FilePlaylistPosition"] = currentFileIndex.ToString();

                    // Embed the PlayableItemId so we can identify which one to track progress for
                    friendlyData["PlayableItemId"] = playable.Id.ToString();

                    // Embed the Media index so we can identify which one to track progress for
                    friendlyData["MediaIndex"] = mediaIndex.ToString();

                    // Set a friendly title
                    friendlyData["Title"] = media.Name;

                    var song = media as Song;

                    if (song != null)
                    {
                        var itemImage = song.PrimaryImagePath;

                        // The following "friendly" data fields are undocumented but working for song items...
                        if (playable.Folder != null)
                        {
                            // This is either a music album or a playlist
                            friendlyData["AlbumTitle"] = playable.Folder.Name;
                            if (string.IsNullOrEmpty(itemImage))
                            {
                                itemImage = playable.Folder.PrimaryImagePath;
                            }
                        }
                        else
                        {
                            friendlyData["AlbumTitle"] = song.Album;
                        }

                        friendlyData["AlbumArtist"] = song.AlbumArtist;
                        friendlyData["Artist"] = song.Artist;
                        friendlyData["TrackNumber"] = currentFileIndex;

                        if (song.PremierDate != DateTime.MinValue)
                        {
                            friendlyData["YearReleased"] = song.PremierDate.Year;
                        }

                        if (!string.IsNullOrEmpty(itemImage))
                        {
                            friendlyData["AlbumCoverUrl"] = itemImage;
                        }
                    }

                    coll.AddItem(path, collectionIndex, -1, string.Empty, friendlyData);
                    
                    currentFileIndex++;
                    collectionIndex++;
                }
            }
        }