Пример #1
0
        public override void OnAction(Action action)
        {
            switch (action.wID)
            {
            case Action.ActionType.ACTION_SHOW_PLAYLIST:
                GUIWindowManager.ShowPreviousWindow();
                return;

            case Action.ActionType.ACTION_MOVE_SELECTED_ITEM_UP:
                MovePlayListItemUp();
                return;

            case Action.ActionType.ACTION_MOVE_SELECTED_ITEM_DOWN:
                MovePlayListItemDown();
                return;

            case Action.ActionType.ACTION_DELETE_SELECTED_ITEM:
                DeletePlayListItem();
                return;

            // Handle case where playlist has been stopped and we receive a player action.
            // This allows us to restart the playback proccess...
            case Action.ActionType.ACTION_MUSIC_PLAY:
            case Action.ActionType.ACTION_NEXT_ITEM:
            case Action.ActionType.ACTION_PAUSE:
            case Action.ActionType.ACTION_PREV_ITEM:
                if (playlistPlayer.CurrentPlaylistType != PlayListType.PLAYLIST_TVSERIES)
                {
                    playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_TVSERIES;
                    if (g_Player.CurrentFile == "")
                    {
                        PlayList playList = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_TVSERIES);
                        if (playList != null && playList.Count > 0)
                        {
                            playlistPlayer.Play(0);
                            UpdateButtonStates();
                        }
                    }
                }
                break;
            }
            base.OnAction(action);
        }
Пример #2
0
        public void Play(string filename)
        {
            if (_currentPlayList == PlayListType.PLAYLIST_NONE)
            {
                return;
            }

            PlayList playlist = GetPlaylist(_currentPlayList);

            for (int i = 0; i < playlist.Count; ++i)
            {
                PlayListItem item = playlist[i];
                if (item.FileName.Equals(filename))
                {
                    Play(i);
                    return;
                }
            }
        }
Пример #3
0
        private void OnSavePlayList()
        {
            currentSelectedItem = m_Facade.SelectedListItemIndex;
            string playlistFileName = string.Empty;

            if (GetKeyboard(ref playlistFileName))
            {
                string playListPath = string.Empty;
                playListPath = DBOption.GetOptions(DBOption.cPlaylistPath);
                playListPath = MediaPortal.Util.Utils.RemoveTrailingSlash(playListPath);

                // check if Playlist folder exists, create it if not
                if (!Directory.Exists(playListPath))
                {
                    try {
                        Directory.CreateDirectory(playListPath);
                    }
                    catch (Exception e) {
                        MPTVSeriesLog.Write("Error: Unable to create Playlist path: " + e.Message);
                        return;
                    }
                }

                string fullPlayListPath = Path.GetFileNameWithoutExtension(playlistFileName);

                fullPlayListPath += ".tvsplaylist";
                if (playListPath.Length != 0)
                {
                    fullPlayListPath = playListPath + @"\" + fullPlayListPath;
                }
                PlayList playlist = new PlayList();
                for (int i = 0; i < m_Facade.Count; ++i)
                {
                    GUIListItem  listItem     = m_Facade[i];
                    PlayListItem playListItem = new PlayListItem();
                    playListItem.Episode = listItem.TVTag as DBEpisode;
                    playlist.Add(playListItem);
                }
                PlayListIO saver = new PlayListIO();
                saver.Save(playlist, fullPlayListPath);
            }
        }
Пример #4
0
        private void OnShufflePlayList()
        {
            currentSelectedItem = m_Facade.SelectedListItemIndex;
            ClearFileItems();
            PlayList playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_TVSERIES);

            if (playlist.Count <= 0)
            {
                return;
            }
            string currentItemFileName = string.Empty;

            if (playlistPlayer.CurrentItem >= 0)
            {
                if (g_Player.Playing && playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_TVSERIES)
                {
                    PlayListItem item = playlist[playlistPlayer.CurrentItem];
                    currentItemFileName = item.FileName;
                }
            }
            playlist.Shuffle();
            if (playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_TVSERIES)
            {
                playlistPlayer.Reset();
            }

            if (currentItemFileName.Length > 0)
            {
                for (int i = 0; i < playlist.Count; i++)
                {
                    PlayListItem playListItem = playlist[i];
                    if (playListItem.FileName == currentItemFileName)
                    {
                        playlistPlayer.CurrentItem = i;
                    }
                }
            }

            LoadDirectory(currentFolder);
        }
Пример #5
0
        public void Save(PlayList playlist, string fileName)
        {
            try
            {
                XmlTextWriter textWriter = new XmlTextWriter(fileName, null);

                textWriter.Formatting  = Formatting.Indented;
                textWriter.Indentation = 4;

                textWriter.WriteStartDocument();
                textWriter.WriteComment("MP-TVSeries playlist");

                // Create a <Playlist> element, to contain a list of episodes in playlist
                textWriter.WriteStartElement("Playlist");

                foreach (PlayListItem item in playlist)
                {
                    // Create an <Episode> element for each episode
                    textWriter.WriteStartElement("Episode");

                    // Store Episode ID, this is all that is required
                    textWriter.WriteStartElement("ID");
                    textWriter.WriteString(item.EpisodeID);
                    textWriter.WriteEndElement();

                    // Close <Episode> element
                    textWriter.WriteEndElement();
                }

                textWriter.WriteEndElement();
                textWriter.WriteEndDocument();
                textWriter.Close();
            }
            catch (Exception e)
            {
                MPTVSeriesLog.Write(string.Format("failed to save a playlist {0}. err: {1} stack: {2}", fileName, e.Message, e.StackTrace));
            }
        }
Пример #6
0
        protected void LoadPlayList(string strPlayList)
        {
            IPlayListIO loader = PlayListFactory.CreateIO(strPlayList);

            if (loader == null)
            {
                return;
            }
            PlayList playlist = new PlayList();

            if (!loader.Load(playlist, strPlayList))
            {
                TVSeriesPlugin.ShowDialogOk(Translation.Playlist, new string[] { GUILocalizeStrings.Get(477) });
                return;
            }

            playlistPlayer.CurrentPlaylistName = System.IO.Path.GetFileNameWithoutExtension(strPlayList);
            if (playlist.Count == 1 && playlistPlayer.PlaylistAutoPlay)
            {
                MPTVSeriesLog.Write(string.Format("GUITVSeriesPlaylist: play single playlist item - {0}", playlist[0].FileName));

                // If the file is an image file, it should be mounted before playing
                string filename = playlist[0].FileName;
                if (Helper.IsImageFile(filename))
                {
                    if (!GUIVideoFiles.MountImageFile(GUIWindowManager.ActiveWindow, filename, false))
                    {
                        return;
                    }
                }

                if (g_Player.Play(filename))
                {
                    if (MediaPortal.Util.Utils.IsVideo(filename))
                    {
                        g_Player.ShowFullScreenWindow();
                    }
                }
                return;
            }

            // clear current playlist
            playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_TVSERIES).Clear();

            // add each item of the playlist to the playlistplayer
            for (int i = 0; i < playlist.Count; ++i)
            {
                PlayListItem playListItem = playlist[i];
                playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_TVSERIES).Add(playListItem);
            }

            // if we got a playlist
            if (playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_TVSERIES).Count > 0)
            {
                playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_TVSERIES);

                // autoshuffle on load
                if (playlistPlayer.PlaylistAutoShuffle)
                {
                    playlist.Shuffle();
                }

                // then get 1st item
                PlayListItem item = playlist[0];

                // and start playing it
                if (playlistPlayer.PlaylistAutoPlay)
                {
                    playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_TVSERIES;
                    playlistPlayer.Reset();
                    playlistPlayer.Play(0);
                }

                // and activate the playlist window if its not activated yet
                if (GetID == GUIWindowManager.ActiveWindow)
                {
                    GUIWindowManager.ActivateWindow(GetID);
                }
            }
        }
Пример #7
0
        protected void LoadDirectory(string strNewDirectory)
        {
            if (m_Facade == null)
            {
                return;
            }

            GUIWaitCursor.Show();
            try
            {
                GUIListItem SelectedItem = m_Facade.SelectedListItem;
                if (SelectedItem != null)
                {
                    if (SelectedItem.IsFolder && SelectedItem.Label != "..")
                    {
                        m_history.Set(SelectedItem.Label, currentFolder);
                    }
                }
                currentFolder = strNewDirectory;
                m_Facade.Clear();

                string strObjects = string.Empty;

                ArrayList itemlist = new ArrayList();

                PlayList playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_TVSERIES);
                /* copy playlist from general playlist*/
                int iCurrentItem = -1;
                if (playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_TVSERIES)
                {
                    iCurrentItem = playlistPlayer.CurrentItem;
                }

                string strFileName;
                for (int i = 0; i < playlist.Count; ++i)
                {
                    PlayListItem item = playlist[i];
                    strFileName = item.FileName;

                    GUIListItem pItem = new GUIListItem(item.EpisodeName);
                    pItem.Path     = strFileName;
                    pItem.IsFolder = false;
                    pItem.TVTag    = item.Episode;

                    // update images
                    pItem.ThumbnailImage = item.EpisodeThumb;
                    //pItem.IconImageBig = item.EpisodeThumb;
                    //pItem.IconImage = item.EpisodeThumb;

                    if (item.IsWatched)
                    {
                        pItem.IsPlayed  = true; // facade colours...dont seem to work!
                        pItem.IconImage = Helper.GetThemedSkinFile(ThemeType.Image, "tvseries_Watched.png");
                    }
                    else
                    {
                        pItem.IsPlayed  = false;
                        pItem.IconImage = Helper.GetThemedSkinFile(ThemeType.Image, "tvseries_UnWatched.png");
                    }

                    if (item.Duration > 0)
                    {
                        double nDuration = item.Duration;
                        if (nDuration > 0)
                        {
                            string str = Helper.MSToMMSS(nDuration);
                            pItem.Label2 = str;
                        }
                        else
                        {
                            pItem.Label2 = string.Empty;
                        }
                    }

                    itemlist.Add(pItem);
                    //MediaPortal.Util.Utils.SetDefaultIcons(pItem);
                }

                iCurrentItem = 0;
                strFileName  = string.Empty;
                //	Search current playlist item
                if ((m_nTempPlayListWindow == GetID && m_strTempPlayListDirectory.IndexOf(currentFolder) >= 0 && g_Player.Playing) ||
                    (GetID == (int)Window.WINDOW_VIDEO_PLAYLIST && playlistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_TVSERIES &&
                     g_Player.Playing))
                {
                    iCurrentItem = playlistPlayer.CurrentItem;
                    if (iCurrentItem >= 0)
                    {
                        playlist = playlistPlayer.GetPlaylist(playlistPlayer.CurrentPlaylistType);
                        if (iCurrentItem < playlist.Count)
                        {
                            PlayListItem item = playlist[iCurrentItem];
                            strFileName = item.FileName;
                        }
                    }
                }

                string strSelectedItem = m_history.Get(currentFolder);
                int    iItem           = 0;
                foreach (GUIListItem item in itemlist)
                {
                    m_Facade.Add(item);
                    item.OnItemSelected += new GUIListItem.ItemSelectedHandler(onFacadeItemSelected);

                    //	synchronize playlist with current directory
                    if (strFileName.Length > 0 && item.Path == strFileName)
                    {
                        item.Selected = true;
                    }
                }
                for (int i = 0; i < m_Facade.Count; ++i)
                {
                    GUIListItem item = m_Facade[i];
                    if (item.Label == strSelectedItem)
                    {
                        GUIControl.SelectItemControl(GetID, m_Facade.GetID, iItem);
                        break;
                    }
                    iItem++;
                }

                //set object count label
                int iTotalItems = itemlist.Count;
                GUIPropertyManager.SetProperty("#itemcount", Translation.Episodes + ": " + iTotalItems.ToString());
                GUIPropertyManager.SetProperty("#TVSeries.Playlist.Count", iTotalItems.ToString());

                if (currentSelectedItem >= 0)
                {
                    GUIControl.SelectItemControl(GetID, m_Facade.GetID, currentSelectedItem);
                }
                UpdateButtonStates();
                GUIWaitCursor.Hide();
            }
            catch (Exception ex)
            {
                GUIWaitCursor.Hide();
                MPTVSeriesLog.Write(string.Format("GUITVSeriesPlaylist: An error occured while loading the directory - {0}", ex.Message));
            }
        }
Пример #8
0
        public bool Play(int iItem)
        {
            // if play returns false PlayNext is called but this does not help against selecting an invalid file
            bool skipmissing = false;

            do
            {
                if (_currentPlayList == PlayListType.PLAYLIST_NONE)
                {
                    MPTVSeriesLog.Write("PlaylistPlayer.Play() no playlist selected", MPTVSeriesLog.LogLevel.Debug);
                    return(false);
                }
                PlayList playlist = GetPlaylist(_currentPlayList);
                if (playlist.Count <= 0)
                {
                    MPTVSeriesLog.Write("PlaylistPlayer.Play() playlist is empty", MPTVSeriesLog.LogLevel.Debug);
                    return(false);
                }
                if (iItem < 0)
                {
                    iItem = 0;
                }
                if (iItem >= playlist.Count)
                {
                    if (skipmissing)
                    {
                        return(false);
                    }
                    else
                    {
                        if (_entriesNotFound < playlist.Count)
                        {
                            iItem = playlist.Count - 1;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }

                _currentItem = iItem;
                PlayListItem item = playlist[_currentItem];

                GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_ITEM_FOCUS, 0, 0, 0, _currentItem, 0, null);
                msg.Label = item.FileName;
                GUIGraphicsContext.SendMessage(msg);

                if (playlist.AllPlayed())
                {
                    playlist.ResetStatus();
                }

                bool playResult = false;

                // If the file is an image file, it should be mounted before playing
                string filename = item.FileName;
                if (Helper.IsImageFile(filename))
                {
                    if (!GUIVideoFiles.MountImageFile(GUIWindowManager.ActiveWindow, filename, false))
                    {
                        return(false);
                    }
                }

                // Start Listening to any External Player Events
                listenToExternalPlayerEvents = true;

                #region Publish Play properties for InfoService plugin
                string seriesName  = item.SeriesName;
                string seasonID    = item.SeasonIndex;
                string episodeID   = item.EpisodeIndex;
                string episodeName = item.EpisodeName;
                GUIPropertyManager.SetProperty("#TVSeries.Extended.Title", string.Format("{0}/{1}/{2}/{3}", seriesName, seasonID, episodeID, episodeName));
                MPTVSeriesLog.Write(string.Format("#TVSeries.Extended.Title: {0}/{1}/{2}/{3}", seriesName, seasonID, episodeID, episodeName));
                #endregion

                // Play File
                playResult = g_Player.Play(filename);

                // Stope Listening to any External Player Events
                listenToExternalPlayerEvents = false;

                if (!playResult)
                {
                    //	Count entries in current playlist
                    //	that couldn't be played
                    _entriesNotFound++;
                    MPTVSeriesLog.Write(string.Format("PlaylistPlayer: *** unable to play - {0} - skipping file!", item.FileName));

                    // do not try to play the next file list
                    if (Utils.IsVideo(item.FileName))
                    {
                        skipmissing = false;
                    }
                    else
                    {
                        skipmissing = true;
                    }

                    iItem++;
                }
                else
                {
                    item.Played    = true;
                    item.IsWatched = true; // for facade watched icons
                    skipmissing    = false;
                    if (Utils.IsVideo(item.FileName))
                    {
                        if (g_Player.HasVideo)
                        {
                            // tell any listeners that we are starting playback
                            if (EpisodeStarted != null)
                            {
                                EpisodeStarted(item.Episode);
                            }

                            g_Player.ShowFullScreenWindow();
                            Thread.Sleep(2000);
                            SetProperties(item, false);
                        }
                    }
                }
            }while (skipmissing);
            return(g_Player.Playing);
        }