public PlayListItem GetNextItem() { if (_currentPlayList == PlayListType.PLAYLIST_NONE) { return(null); } PlayList playlist = GetPlaylist(_currentPlayList); if (playlist.Count <= 0) { return(null); } int iItem = _currentItem; iItem++; if (iItem >= playlist.Count) { if (!_repeatPlayList) { return(null); } iItem = 0; } PlayListItem item = playlist[iItem]; return(item); }
public string Get(int iItem) { if (_currentPlayList == PlayListType.PLAYLIST_NONE) { return(string.Empty); } PlayList playlist = GetPlaylist(_currentPlayList); if (playlist.Count <= 0) { return(string.Empty); } if (iItem >= playlist.Count) { if (!_repeatPlayList) { return(string.Empty);; } iItem = 0; } PlayListItem item = playlist[iItem]; return(item.FileName); }
public string GetNext() { PlayListItem resultingItem = GetNextItem(); if (resultingItem != null) { return(resultingItem.FileName); } else { return(string.Empty); } }
private bool AddItem(string episodeID) { SQLCondition condition = new SQLCondition(); condition.Add(new DBOnlineEpisode(), DBOnlineEpisode.cID, episodeID, SQLConditionType.Equal); List <DBEpisode> ep = DBEpisode.Get(condition, false); if (ep.Count > 0) { PlayListItem newItem = new PlayListItem(ep[0]); playlist.Add(newItem); } return(true); }
private void SetAsWatched() { PlayListItem item = GetCurrentItem(); if (item == null) { return; } // notify listeners if (EpisodeWatched != null) { EpisodeWatched(item.Episode); } item.Watched = true; }
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; } } }
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); } }
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); }
/// <summary> /// Play all episodes of a series /// </summary> /// <param name="seriesId">ID of a series</param> /// <param name="onlyUnwatched">Play only unwatched episodes</param> /// <param name="autostart">If yes, automatically starts playback with the first episode</param> /// <param name="startIndex">Index of the item with which playback should start</param> /// <param name="switchToPlaylistView">If yes the playlistview will be shown</param> public static void PlaySeries(int seriesId, bool autostart, int startIndex, bool onlyUnwatched, bool switchToPlaylistView) { if (GUIGraphicsContext.form.InvokeRequired) { PlaySeriesAsyncDelegate d = new PlaySeriesAsyncDelegate(PlaySeries); GUIGraphicsContext.form.Invoke(d, new object[] { seriesId, autostart, startIndex, onlyUnwatched, switchToPlaylistView }); return; } List<DBEpisode> episodes = DBEpisode.Get(seriesId); if (episodes == null || episodes.Count == 0) return; // filter out anything we can't play episodes.RemoveAll(e => string.IsNullOrEmpty(e[DBEpisode.cFilename])); // filter out watched episodes if (onlyUnwatched) { episodes.RemoveAll(e => e[DBOnlineEpisode.cWatched] != 0); } if (episodes.Count == 0) return; // Sort episodes and add them to the MP-TVSeries playlist player // Setup playlist player if (playlistPlayer == null) { playlistPlayer = PlayListPlayer.SingletonPlayer; playlistPlayer.PlaylistAutoPlay = true; playlistPlayer.RepeatPlaylist = DBOption.GetOptions(DBOption.cRepeatPlaylist); } playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_TVSERIES).Clear(); episodes.Sort(); foreach (DBEpisode episode in episodes) { PlayListItem playlistItem = new PlayListItem(episode); playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_TVSERIES).Add(playlistItem); } //automatically start playing the playlist if (autostart) { // and activate the playlist window if its not activated yet if (switchToPlaylistView) { GUIWindowManager.ActivateWindow(GUITVSeriesPlayList.GetWindowID); } playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_TVSERIES; playlistPlayer.Reset(); playlistPlayer.Play(0); } }
protected void AddItemToPlayList() { if (_playlistPlayer == null) { _playlistPlayer = PlayListPlayer.SingletonPlayer; _playlistPlayer.PlaylistAutoPlay = DBOption.GetOptions(DBOption.cPlaylistAutoPlay); _playlistPlayer.RepeatPlaylist = DBOption.GetOptions(DBOption.cRepeatPlaylist); } SQLCondition condition = new SQLCondition(); List<DBEpisode> episodes; if (this.listLevel == Listlevel.Group) { return; } else if (this.listLevel == Listlevel.Series && m_SelectedSeries != null) { condition.Add(new DBEpisode(), DBEpisode.cSeriesID, m_SelectedSeries[DBSeries.cID], SQLConditionType.Equal); if (DBOption.GetOptions(DBOption.cPlaylistUnwatchedOnly)) condition.Add(new DBOnlineEpisode(), DBOnlineEpisode.cWatched, false, SQLConditionType.Equal); } else if (this.listLevel == Listlevel.Season && m_SelectedSeason != null) { condition.Add(new DBEpisode(), DBEpisode.cSeriesID, m_SelectedSeries[DBSeries.cID], SQLConditionType.Equal); condition.Add(new DBEpisode(), DBEpisode.cSeasonIndex, m_SelectedSeason[DBSeason.cIndex], SQLConditionType.Equal); if (DBOption.GetOptions(DBOption.cPlaylistUnwatchedOnly)) condition.Add(new DBOnlineEpisode(), DBOnlineEpisode.cWatched, false, SQLConditionType.Equal); } else if (this.listLevel == Listlevel.Episode && m_SelectedEpisode != null) { condition.Add(new DBEpisode(), DBEpisode.cSeriesID, m_SelectedSeries[DBSeries.cID], SQLConditionType.Equal); condition.Add(new DBEpisode(), DBEpisode.cSeasonIndex, m_SelectedSeason[DBSeason.cIndex], SQLConditionType.Equal); condition.Add(new DBEpisode(), DBEpisode.cEpisodeIndex, m_SelectedEpisode[DBEpisode.cEpisodeIndex], SQLConditionType.Equal); } episodes = DBEpisode.Get(condition, false); episodes.Sort(); foreach (DBEpisode episode in episodes) { PlayListItem playlistItem = new PlayListItem(episode); _playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_TVSERIES).Add(playlistItem); } // Select next item in list int item = m_Facade.SelectedListItemIndex; if (item < m_Facade.Count) m_Facade.SelectedListItemIndex = item + 1; }
private bool AddItem(string episodeID) { SQLCondition condition = new SQLCondition(); condition.Add(new DBOnlineEpisode(), DBOnlineEpisode.cID, episodeID, SQLConditionType.Equal); List<DBEpisode> ep = DBEpisode.Get(condition, false); if (ep.Count > 0) { PlayListItem newItem = new PlayListItem(ep[0]); playlist.Add(newItem); } return true; }
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); } } }
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)); } }
/// <summary> /// Updates the movie metadata on the playback screen (for when the user clicks info). /// The delay is neccesary because Player tries to use metadata from the MyVideos database. /// We want to update this after that happens so the correct info is there. /// </summary> /// <param name="item">Playlist item</param> /// <param name="clear">Clears the properties instead of filling them if True</param> private void SetProperties(PlayListItem item, bool clear) { if (item == null) { return; } string title = string.Empty; DBSeries series = null; DBSeason season = null; if (!clear) { title = string.Format("{0} - {1}x{2} - {3}", item.SeriesName, item.SeasonIndex, item.EpisodeIndex, item.EpisodeName); series = Helper.getCorrespondingSeries(item.Episode[DBEpisode.cSeriesID]); season = Helper.getCorrespondingSeason(item.Episode[DBEpisode.cSeriesID], int.Parse(item.SeasonIndex)); } // Show Plot in OSD or Hide Spoilers (note: FieldGetter takes care of that) GUIPropertyManager.SetProperty("#Play.Current.Plot", clear ? " " : FieldGetter.resolveDynString(TVSeriesPlugin.m_sFormatEpisodeMain, item.Episode)); // Show Episode Thumbnail or Series Poster if Hide Spoilers is enabled string osdImage = string.Empty; if (!clear) { foreach (KeyValuePair <string, string> kvp in SkinSettings.VideoOSDImages) { switch (kvp.Key) { case "episode": osdImage = ImageAllocator.GetEpisodeImage(item.Episode); break; case "season": osdImage = season.Banner; break; case "series": osdImage = series.Poster; break; case "custom": string value = replaceDynamicFields(kvp.Value, item.Episode); string file = Helper.getCleanAbsolutePath(value); if (System.IO.File.Exists(file)) { osdImage = file; } break; } osdImage = osdImage.Trim(); if (string.IsNullOrEmpty(osdImage)) { continue; } else { break; } } } GUIPropertyManager.SetProperty("#Play.Current.Thumb", clear ? " " : osdImage); foreach (KeyValuePair <string, string> kvp in SkinSettings.VideoPlayImages) { if (!clear) { string value = replaceDynamicFields(kvp.Value, item.Episode); string file = Helper.getCleanAbsolutePath(value); if (System.IO.File.Exists(file)) { MPTVSeriesLog.Write(string.Format("Setting play image {0} for property {1}", file, kvp.Key), MPTVSeriesLog.LogLevel.Debug); GUIPropertyManager.SetProperty(kvp.Key, clear ? " " : file); } } else { MPTVSeriesLog.Write(string.Format("Clearing play image for property {0}", kvp.Key), MPTVSeriesLog.LogLevel.Debug); GUIPropertyManager.SetProperty(kvp.Key, " "); } } GUIPropertyManager.SetProperty("#Play.Current.Title", clear ? "" : title); GUIPropertyManager.SetProperty("#Play.Current.Year", clear ? "" : FieldGetter.resolveDynString("<" + DBEpisode.cOutName + "." + DBOnlineEpisode.cFirstAired + ">", item.Episode, false)); GUIPropertyManager.SetProperty("#Play.Current.Genre", clear ? "" : FieldGetter.resolveDynString(TVSeriesPlugin.m_sFormatEpisodeSubtitle, item.Episode)); }
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); }
public void OnMessage(GUIMessage message) { switch (message.Message) { case GUIMessage.MessageType.GUI_MSG_PLAYBACK_STOPPED: { PlayListItem item = GetCurrentItem(); if (item != null) { // notify listeners if (EpisodeStopped != null) { EpisodeStopped(item.Episode); } Reset(); _currentPlayList = PlayListType.PLAYLIST_NONE; SetProperties(item, true); } GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_ITEM_FOCUS, 0, 0, 0, -1, 0, null); GUIGraphicsContext.SendMessage(msg); } break; case GUIMessage.MessageType.GUI_MSG_PLAYBACK_ENDED: { SetAsWatched(); PlayNext(); if (!g_Player.Playing) { g_Player.Release(); // Clear focus when playback ended GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_ITEM_FOCUS, 0, 0, 0, -1, 0, null); GUIGraphicsContext.SendMessage(msg); } } break; case GUIMessage.MessageType.GUI_MSG_PLAY_FILE: { MPTVSeriesLog.Write(string.Format("Playlistplayer: Start file ({0})", message.Label)); g_Player.Play(message.Label); if (!g_Player.Playing) { g_Player.Stop(); } } break; case GUIMessage.MessageType.GUI_MSG_STOP_FILE: { MPTVSeriesLog.Write(string.Format("Playlistplayer: Stop file")); g_Player.Stop(); } break; case GUIMessage.MessageType.GUI_MSG_SEEK_FILE_PERCENTAGE: { MPTVSeriesLog.Write(string.Format("Playlistplayer: SeekPercent ({0}%)", message.Param1)); g_Player.SeekAsolutePercentage(message.Param1); MPTVSeriesLog.Write(string.Format("Playlistplayer: SeekPercent ({0}%) done", message.Param1), MPTVSeriesLog.LogLevel.Debug); } break; case GUIMessage.MessageType.GUI_MSG_SEEK_FILE_END: { double duration = g_Player.Duration; double position = g_Player.CurrentPosition; if (position < duration - 1d) { MPTVSeriesLog.Write(string.Format("Playlistplayer: SeekEnd ({0})", duration)); g_Player.SeekAbsolute(duration - 2d); MPTVSeriesLog.Write(string.Format("Playlistplayer: SeekEnd ({0}) done", g_Player.CurrentPosition), MPTVSeriesLog.LogLevel.Debug); } } break; case GUIMessage.MessageType.GUI_MSG_SEEK_POSITION: { g_Player.SeekAbsolute(message.Param1); } break; } }