/// <summary> /// Adds songs to a playlist by querying the music database /// </summary> /// <param name="type">Type of the playlist</param> /// <param name="where">SQL where condition</param> /// <param name="limit">Maximum number of songs</param> /// <param name="shuffle"><code>true</code> to shuffle the playlist</param> /// <param name="startIndex">Index to at the songs at</param> public static void AddSongsToPlaylistWithSQL(string type, string where, int limit, bool shuffle, int startIndex) { // Only works for music atm PlayListType plType = GetTypeFromString(type); if (plType == PlayListType.PLAYLIST_MUSIC) { List <Song> songs = new List <Song>(); string sql = "select * from tracks where " + where; if (shuffle) { sql += " ORDER BY random()"; } MusicDatabase.Instance.GetSongsByFilter(sql, out songs, "tracks"); if (songs.Count > 0) { PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; int numberOfSongsAvailable = songs.Count - 1; // Limit 0 means unlimited if (limit == 0) { limit = songs.Count; } for (int i = 0; i < limit && i < songs.Count; i++) { PlayListItem playListItem = ToPlayListItem(songs[i]); playListPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC).Insert(playListItem, startIndex + i); } } } }
/// <summary> /// Private method to start playlist (needed for the invoke callback) /// </summary> private static void StartPlayingPlaylist(bool switchToPlaylistView) { if (GUIGraphicsContext.form.InvokeRequired) { StartPlayingPlaylistDelegate d = StartPlayingPlaylist; GUIGraphicsContext.form.Invoke(d, new object[] { switchToPlaylistView }); } else { PlayListPlayer playlistPlayer = PlayListPlayer.SingletonPlayer; PlayList playlist = playlistPlayer.GetPlaylist(mPlaylistStartType); // if we got a playlist if (playlist.Count > 0) { // and activate the playlist window if its not activated yet if (switchToPlaylistView) { if (mPlaylistStartType == PlayListType.PLAYLIST_MUSIC) { WindowPluginHelper.ActivateWindow((int)MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_MUSIC_PLAYLIST); } else if (mPlaylistStartType == PlayListType.PLAYLIST_VIDEO) { WindowPluginHelper.ActivateWindow((int)MediaPortal.GUI.Library.GUIWindow.Window.WINDOW_VIDEO_PLAYLIST); } } // and start playing it playlistPlayer.CurrentPlaylistType = mPlaylistStartType; playlistPlayer.Reset(); playlistPlayer.Play(mPlaylistStartIndex); } } }
public StreamControl() { AudioscrobblerBase.RadioHandshakeSuccess += new AudioscrobblerBase.RadioHandshakeCompleted(OnRadioLoginSuccess); AudioscrobblerBase.RadioHandshakeError += new AudioscrobblerBase.RadioHandshakeFailed(OnRadioLoginFailed); PlaylistPlayer = PlayListPlayer.SingletonPlayer; }
/// <summary> /// Save the current playlist to file /// </summary> /// <param name="name">Name of new playlist</param> internal static void SaveCurrentPlaylist(string name) { try { using (MediaPortal.Profile.Settings reader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) { string playlistFolder = reader.GetValueAsString("music", "playlists", ""); if (!Path.IsPathRooted(playlistFolder)) { playlistFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), playlistFolder); } PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; PlayList playList = playListPlayer.GetPlaylist(playListPlayer.CurrentPlaylistType); String fileName = Path.Combine(playlistFolder, name + ".m3u"); PlayListM3uIO m3uPlayList = new PlayListM3uIO(); m3uPlayList.Save(playList, fileName); } } catch (Exception ex) { WifiRemote.LogMessage("Error saving playlist: " + ex.ToString(), WifiRemote.LogType.Warn); } }
/// <summary> /// Retrieves the repeat mode of the playlist /// </summary> /// <param name="type">Type of the playlist</param> public static bool GetPlaylistRepeat(String type) { PlayListType plType = GetTypeFromString(type); PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; return(playListPlayer.RepeatPlaylist); }
/// <summary> /// Gets the playlist for a given type /// </summary> /// <param name="type">Type of the playlist</param> /// <returns>List of all playlist items</returns> public static List <PlaylistEntry> GetPlaylistItems(String type) { PlayListType plType = GetTypeFromString(type); PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; PlayList playList = playListPlayer.GetPlaylist(plType); List <PlaylistEntry> retList = new List <PlaylistEntry>(); foreach (PlayListItem item in playList) { PlaylistEntry entry = new PlaylistEntry(); entry.FileName = item.FileName; entry.Name = item.Description; entry.Duration = item.Duration; entry.Played = item.Played; if (item.Type == PlayListItem.PlayListItemType.Audio) { MpMusicHelper.AddMpExtendedInfo(item, entry); } retList.Add(entry); } return(retList); }
/// <summary> /// Retrieves the name of the playlist /// </summary> /// <param name="type">Type of the playlist</param> public static String GetPlaylistName(String type) { PlayListType plType = GetTypeFromString(type); PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; PlayList playList = playListPlayer.GetPlaylist(plType); WifiRemote.LogMessage("Playlist name test:" + playList.Name, WifiRemote.LogType.Debug); return(playList.Name); }
public void InsertItemButNotStartPlayingGivesNull() { PlayListPlayer player = new PlayListPlayer(); player.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC; PlayList playlist = player.GetPlaylist(PlayListType.PLAYLIST_MUSIC); PlayListItem item1 = new PlayListItem(); playlist.Add(item1); Assert.IsNull(player.GetCurrentItem()); }
public void GetNextReturnsFileName() { PlayListPlayer player = new PlayListPlayer(); player.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC; PlayList playlist = player.GetPlaylist(PlayListType.PLAYLIST_MUSIC); PlayListItem item1 = new PlayListItem("apa", "c:\\apa.mp3"); playlist.Add(item1); Assert.AreEqual("c:\\apa.mp3", player.GetNext()); }
public GUIVideoBaseWindow() { playlistPlayer = PlayListPlayer.SingletonPlayer; if (handler == null) { handler = new VideoViewHandler(); } GUIWindowManager.OnNewAction += new OnActionHandler(OnNewAction); }
public override int RenderVisualization() { try { if (VisualizationWindow == null || !VisualizationWindow.Visible || _visParam.VisHandle == 0) { return(0); } // Set Song information, so that the plugin can display it if (trackTag != null && Bass != null) { _playlistPlayer = PlayListPlayer.SingletonPlayer; PlayListItem curPlaylistItem = _playlistPlayer.GetCurrentItem(); _mediaInfo.Position = (int)Bass.CurrentPosition; _mediaInfo.Duration = (int)Bass.Duration; _mediaInfo.PlaylistLen = 1; _mediaInfo.PlaylistPos = _playlistPlayer.CurrentPlaylistPos; } else { _mediaInfo.Position = 0; _mediaInfo.Duration = 0; _mediaInfo.PlaylistLen = 0; _mediaInfo.PlaylistPos = 0; } if (IsPreviewVisualization) { _mediaInfo.SongTitle = "Mediaportal Preview"; } BassVis.BASSVIS_SetInfo(_visParam, _mediaInfo); if (RenderStarted) { return(1); } int stream = 0; if (Bass != null) { stream = (int)Bass.GetCurrentVizStream(); } BassVis.BASSVIS_SetPlayState(_visParam, BASSVIS_PLAYSTATE.Play); RenderStarted = BassVis.BASSVIS_RenderChannel(_visParam, stream); } catch (Exception) {} return(1); }
public GUIMusicPlayingNow() { GetID = (int)Window.WINDOW_MUSIC_PLAYING_NOW; PlaylistPlayer = PlayListPlayer.SingletonPlayer; ImagePathContainer = new List <string>(); _imageMutex = new object(); g_Player.PlayBackStarted += OnPlayBackStarted; g_Player.PlayBackStopped += OnPlayBackStopped; g_Player.PlayBackEnded += OnPlayBackEnded; LoadSettings(); }
/// <summary> /// Clears the playlist (removes all entries) /// </summary> /// <param name="type">Type of the playlist</param> public static void ClearPlaylist(String type, bool refresh) { PlayListType plType = GetTypeFromString(type); PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; PlayList playList = playListPlayer.GetPlaylist(plType); playList.Clear(); if (refresh) { RefreshPlaylistIfVisible(); } }
public override bool Init() { _playlistPlayer = PlayListPlayer.SingletonPlayer; g_Player.PlayBackEnded += OnPlayBackEnded; g_Player.PlayBackChanged += OnPlayBackChanged; g_Player.PlayBackStopped += OnPlayBackStopped; var mdb = MusicDatabase.Instance; var sessionKey = mdb.GetLastFMSK(); var currentUser = mdb.GetLastFMUser(); var a = new LastFMLibrary(sessionKey, currentUser); //TODO this is just making _SK get loaded. No need to actual instansiate return(Load(GUIGraphicsContext.GetThemedSkinDirectory(@"\lastFmRadio.xml"))); }
public void PlayMovesCurrentToItem() { PlayListPlayer player = new PlayListPlayer(); player.g_Player = this; //fake g_Player player.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC; PlayList playlist = player.GetPlaylist(PlayListType.PLAYLIST_MUSIC); PlayListItem item1 = new PlayListItem(); playlist.Add(item1); player.PlayNext(); Assert.AreEqual(item1, player.GetCurrentItem()); Assert.IsTrue(hasPlayBeenCalled); }
/// <summary> /// Removes a song (identified by index in the playlist) from the playlist /// </summary> /// <param name="type">Type of the playlist</param> /// <param name="index">Index that should be removed</param> public static void RemoveItemFromPlaylist(String type, int index) { PlayListType plType = GetTypeFromString(type); PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; PlayList playList = playListPlayer.GetPlaylist(plType); if (playList.Count > index) { PlayListItem item = playList[index]; playList.Remove(item.FileName); } RefreshPlaylistIfVisible(); }
/// <summary> /// Set repeat if type is of the current playlist type /// </summary> /// <param name="type">Type of the playlist</param> public static void Repeat(string type, bool repeat) { WifiRemote.LogMessage("Set playlist repeat:" + repeat, WifiRemote.LogType.Debug); PlayListType plType = GetTypeFromString(type); WifiRemote.LogMessage("plType:" + plType, WifiRemote.LogType.Debug); WifiRemote.LogMessage("currentType:" + PlayListPlayer.SingletonPlayer.CurrentPlaylistType, WifiRemote.LogType.Debug); if (plType == PlayListPlayer.SingletonPlayer.CurrentPlaylistType) { PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; playListPlayer.RepeatPlaylist = repeat; RefreshPlaylistIfVisible(); } }
public GUIMusicOverlay() { GetID = (int)Window.WINDOW_MUSIC_OVERLAY; playlistPlayer = PlayListPlayer.SingletonPlayer; _useBassEngine = BassMusicPlayer.IsDefaultMusicPlayer; using (Profile.Settings xmlreader = new Profile.MPSettings()) { _settingVisEnabled = xmlreader.GetValueAsBool("musicfiles", "doVisualisation", false) && _useBassEngine; _visualisationEnabled = _settingVisEnabled; _stripArtistPrefixes = xmlreader.GetValueAsBool("musicfiles", "stripartistprefixes", false); } g_Player.PlayBackStarted += OnPlayBackStarted; g_Player.PlayBackEnded += OnPlayBackEnded; }
/// <summary> /// Load a playlist from disc. /// </summary> /// <param name="type">Type of the playlist</param> /// <param name="name">Name of the playlist (file)</param> /// <param name="shuffle"><code>true</code> to shuffle the playlist</param> public static void LoadPlaylist(string type, string name, bool shuffle) { // Only working for music atm PlayListType plType = GetTypeFromString(type); if (plType == PlayListType.PLAYLIST_MUSIC) { string playlistPath = String.Empty; // Playlist path supplied if (name.EndsWith(".m3u")) { playlistPath = name; } // Playlist name supplied else { // Get playlist folder from mp config using (MediaPortal.Profile.Settings reader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MediaPortal.xml"))) { string playlistFolder = reader.GetValueAsString("music", "playlists", ""); if (!Path.IsPathRooted(playlistFolder)) { playlistFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), playlistFolder); } playlistPath = Path.Combine(playlistFolder, name + ".m3u"); } } if (File.Exists(playlistPath)) { // Load playlist from file PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; PlayList playList = playListPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC); PlayListM3uIO m3uPlayList = new PlayListM3uIO(); m3uPlayList.Load(playList, playlistPath); // Shuffle playlist if (shuffle) { Shuffle(type); } } } }
/// <summary> /// Adds a song to a playlist /// </summary> /// <param name="type">Type of the playlist</param> /// <param name="entry">Item that gets added</param> /// <param name="index">Index where the item should be added</param> /// <param name="refresh">Should the playlist be refreshed after the item is added</param> public static void AddItemToPlaylist(String type, PlaylistEntry entry, int index, bool refresh) { PlayListType plType = GetTypeFromString(type); PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; PlayList playList = playListPlayer.GetPlaylist(plType); PlayListItem item = null; //If it's a music item, try to find it in the db if (plType == PlayListType.PLAYLIST_MUSIC) { MusicDatabase mpMusicDb = MusicDatabase.Instance; Song song = new Song(); bool inDb = mpMusicDb.GetSongByFileName(entry.FileName, ref song); if (inDb) { item = ToPlayListItem(song); } } else if (plType == PlayListType.PLAYLIST_VIDEO) { IMDBMovie movie = new IMDBMovie(); int id = VideoDatabase.GetMovieInfo(entry.FileName, ref movie); if (id > 0) { item = ToPlayListItem(movie); } } if (item == null) { item = new PlayListItem(entry.Name, entry.FileName, entry.Duration); } playList.Insert(item, index); if (refresh) { RefreshPlaylistIfVisible(); } }
/// <summary> /// Add a list of playlist items to the current playlist /// </summary> /// <param name="type">Type of playlist (e.g. video/music)</param> /// <param name="items">Items that we want to add</param> /// <param name="startIndex">Where should the items be added (-1 will append them at the end)</param> internal static void AddPlaylistItems(PlayListType type, List <PlayListItem> items, int startIndex) { PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; PlayList playList = playListPlayer.GetPlaylist(type); if (startIndex == -1 || startIndex >= playList.Count) { startIndex = playList.Count; } else if (startIndex < 0) { startIndex = 0; } for (int i = 0; i < items.Count; i++) { //Note: we need -1 here, because Insert wants the item after which the song should be inserted, not the actual index playList.Insert(items[i], i + startIndex - 1); } }
/// <summary> /// Changes the position of an item in the playlist /// </summary> /// <param name="type">Type of the playlist</param> /// <param name="oldIndex">Current position of item</param> /// <param name="newIndex">Target position of item</param> public static void ChangePlaylistItemPosition(String type, int oldIndex, int newIndex) { PlayListType plType = GetTypeFromString(type); PlayListPlayer playListPlayer = PlayListPlayer.SingletonPlayer; PlayList playList = playListPlayer.GetPlaylist(plType); if (oldIndex >= 0 && newIndex >= 0 && playList.Count > oldIndex && playList.Count > newIndex) { WifiRemote.LogMessage("Change playlist index " + oldIndex + " to " + newIndex, WifiRemote.LogType.Debug); PlayListItem item = playList[oldIndex]; playList.Remove(item.FileName); //Note: we need -1 here, because Insert wants the item after which the song should be inserted, not the actual index playList.Insert(item, newIndex - 1); RefreshPlaylistIfVisible(); } else { WifiRemote.LogMessage("Index for changing playlistPosition invalid (old: " + oldIndex + ", new: " + newIndex + ")", WifiRemote.LogType.Warn); } }
public GUITVSeriesPlayList() { GetID = (int) Window.WINDOW_VIDEO_PLAYLIST; playlistPlayer = PlayListPlayer.SingletonPlayer; m_directory.AddDrives(); m_directory.SetExtensions(Utils.VideoExtensions); m_directory.AddExtension(".tvsplaylist"); }
public override int RenderVisualization() { try { if (VisualizationWindow == null || !VisualizationWindow.Visible || _visParam.VisHandle == 0) { return(0); } // Any is wrong with PlaybackStateChanged, if the songfile automatically changed // so i have create a new variable which fix this problem if (Bass != null) { if (Bass.CurrentFile != _OldCurrentFile && !Bass.IsRadio) { trackTag = TagReader.TagReader.ReadTag(Bass.CurrentFile); if (trackTag != null) { _songTitle = String.Format("{0} - {1}", trackTag.Artist, trackTag.Title); _OldCurrentFile = Bass.CurrentFile; } else { _songTitle = " "; } } // Set Song information, so that the plugin can display it if (trackTag != null && !Bass.IsRadio) { _playlistPlayer = PlayListPlayer.SingletonPlayer; PlayListItem curPlaylistItem = _playlistPlayer.GetCurrentItem(); MusicStream streams = Bass.GetCurrentStream(); // Do not change this line many Plugins search for Songtitle with a number before. _mediaInfo.SongFile = Bass.CurrentFile; _mediaInfo.SongTitle = (_playlistPlayer.CurrentPlaylistPos + 1) + ". " + _songTitle; _mediaInfo.Position = (int)(1000 * Bass.CurrentPosition); _mediaInfo.Duration = (int)Bass.Duration; _mediaInfo.PlaylistLen = 1; _mediaInfo.PlaylistPos = _playlistPlayer.CurrentPlaylistPos; } else { if (Bass.IsRadio) { // Change TrackTag to StreamTag for Radio trackTag = Bass.GetStreamTags(); if (trackTag != null) { // Artist and Title show better i think _songTitle = trackTag.Artist + ": " + trackTag.Title; _mediaInfo.SongTitle = _songTitle; } else { _songTitle = " "; } _mediaInfo.Position = (int)(1000 * Bass.CurrentPosition); } else { _mediaInfo.Position = 0; _mediaInfo.Duration = 0; _mediaInfo.PlaylistLen = 0; _mediaInfo.PlaylistPos = 0; } } } if (IsPreviewVisualization) { _mediaInfo.SongTitle = "Mediaportal Preview"; } BassVis.BASSVIS_SetInfo(_visParam, _mediaInfo); if (RenderStarted) { return(1); } int stream = 0; if (Bass != null) { stream = (int)Bass.GetCurrentVizStream(); } // ckeck is playing int nReturn = BassVis.BASSVIS_SetPlayState(_visParam, BASSVIS_PLAYSTATE.IsPlaying); if (nReturn == Convert.ToInt32(BASSVIS_PLAYSTATE.Play) && (_visParam.VisHandle != 0)) { // Do not Render without playing if (MusicPlayer.BASS.Config.MusicPlayer == AudioPlayer.WasApi) { RenderStarted = BassVis.BASSVIS_RenderChannel(_visParam, stream, true); } else { RenderStarted = BassVis.BASSVIS_RenderChannel(_visParam, stream, false); } } } catch (Exception) {} return(1); }
/// <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); } }
public GUIMusicFullscreen() { GetID = (int)Window.WINDOW_FULLSCREEN_MUSIC; playlistPlayer = PlayListPlayer.SingletonPlayer; }
/// <summary> /// Static Constructor for the Playlistplayer instance /// </summary> static MPlayerGUIPlugin() { PlaylistPlayer = PlayListPlayer.SingletonPlayer; }