public void Init(List <string> items)
        {
            ItemsToPlay.Clear();
            var pos = 0;

            foreach (var item in items)
            {
                ItemsToPlay.AddItem(item, pos, 0xffff);
                pos++;
            }
        }
Exemple #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++;
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// When playback is based purely on file paths, this will populate the MediaCollection using the paths
        /// </summary>
        public static void PopulateMediaCollectionUsingFiles(MediaCollection coll, PlayableItem playable, int startIndex, int count)
        {
            int    numFiles = playable.Files.Count();
            string idString = playable.Id.ToString();

            // Create a MediaCollectionItem for each file to play
            for (int i = startIndex; i < count; i++)
            {
                string path = playable.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"] = i.ToString();

                // Embed the PlayableItemId so we can identify which one to track progress for
                friendlyData["PlayableItemId"] = idString;

                coll.AddItem(path, i, -1, string.Empty, friendlyData);
            }
        }
        /// <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>
        /// When playback is based purely on file paths, this will populate the MediaCollection using the paths
        /// </summary>
        public static void PopulateMediaCollectionUsingFiles(MediaCollection coll, PlayableItem playable, int startIndex, int count)
        {
            int numFiles = playable.Files.Count();
            string idString = playable.Id.ToString();

            // Create a MediaCollectionItem for each file to play
            for (int i = startIndex; i < count; i++)
            {
                string path = playable.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"] = i.ToString();

                // Embed the PlayableItemId so we can identify which one to track progress for
                friendlyData["PlayableItemId"] = idString;

                coll.AddItem(path, i, -1, string.Empty, friendlyData);
            }
        }
Exemple #6
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++;
                }
            }
        }
        public bool Play(BaseItem item)
        {
            var coll = new MediaCollection();
            if (item.ThemeVideos != null)
            {
                for (var i = 0; i < Config.Instance.ThemeBackgroundRepeat; i++ )
                {
                    item.ThemeVideos.ForEach(v => coll.AddItem(v.Path));
                }

                IsPlayingVideo = true;
            }

            else if (item.ThemeSongs != null)
            {
                for (var i = 0; i < Config.Instance.ThemeBackgroundRepeat; i++)
                {
                    item.ThemeSongs.ForEach(a => coll.AddItem(a.Path));
                }

                IsPlayingVideo = false;
            }
            else if (Config.Instance.PlayTrailerAsBackground)
            {
                var movie = item as Movie;
                if (movie != null && movie.TrailerFiles.Any())
                {
                    for (var i = 0; i < Config.Instance.ThemeBackgroundRepeat; i++)
                    {
                        foreach (var trailerFile in movie.TrailerFiles)
                        {
                            coll.AddItem(trailerFile);
                        }
                    }

                    IsPlayingVideo = true;
                }
            }

            if (coll.Any())
            {
                //stop anything currently playing
                PlaybackControllerHelper.Stop();

                var mce = AddInHost.Current.MediaCenterEnvironment;
                mce.PropertyChanged += EnvironmentPropertyChange;

                if (mce.PlayMedia(MediaType.MediaCollection, coll, false))
                {
                    IsPlaying = true;
                    Application.CurrentInstance.ShowNowPlaying = IsPlayingVideo;
                    CurrentScope = item;
                    return true;
                }
                else
                {
                    mce.PropertyChanged -= EnvironmentPropertyChange;
                }
            }

            return false;
        }
        private void PlayInternal(BaseItem item)
        {
            if (!item.ThemesLoaded)
            {
                item.LoadThemes();
            }

            var coll = new MediaCollection();

            if (item.ThemeVideos != null && item.ThemeVideos.Count > 0)
            {
                for (var i = 0; i < Config.Instance.ThemeBackgroundRepeat; i++)
                {
                    item.ThemeVideos.ForEach(v => coll.AddItem(v.Path));
                }

                IsPlayingVideo = true;
            }

            else if (item.ThemeSongs != null && item.ThemeSongs.Count > 0)
            {
                for (var i = 0; i < Config.Instance.ThemeBackgroundRepeat; i++)
                {
                    item.ThemeSongs.ForEach(a => coll.AddItem(a.Path));
                }

                IsPlayingVideo = false;
            }
            else if (Config.Instance.PlayTrailerAsBackground)
            {
                var movie = item as Movie;
                if (movie != null && movie.TrailerFiles.Any())
                {
                    for (var i = 0; i < Config.Instance.ThemeBackgroundRepeat; i++)
                    {
                        foreach (var trailerFile in movie.TrailerFiles)
                        {
                            coll.AddItem(trailerFile);
                        }
                    }

                    IsPlayingVideo = true;
                }
            }

            if (coll.Any())
            {
                Application.UIDeferredInvokeIfRequired(() =>
                {
                    //stop anything currently playing
                    PlaybackControllerHelper.Stop();

                    var mce              = Application.MediaCenterEnvironment;
                    mce.PropertyChanged += EnvironmentPropertyChange;

                    if (mce.PlayMedia(MediaType.MediaCollection, coll, false))
                    {
                        IsPlaying = true;
                        Application.CurrentInstance.ShowNowPlaying = IsPlayingVideo;
                        CurrentScope = item;
                    }
                    else
                    {
                        mce.PropertyChanged -= EnvironmentPropertyChange;
                    }
                });
            }
        }
        /// <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++;
                }
            }
        }