public void LoadM3U() { PlayList playlist = new PlayList(); IPlayListIO loader = new PlayListM3uIO(); Assert.IsTrue(loader.Load(playlist, "Core\\Playlists\\TestData\\exampleList.m3u"), "playlist could not even load!"); Assert.IsTrue(playlist[0].FileName.EndsWith("Bob Marley - 01 - Judge Not.mp3")); Assert.IsTrue(playlist[1].FileName.EndsWith("Bob Marley - 02 - One Cup of Coffee.mp3")); Assert.IsTrue(playlist[2].FileName.EndsWith("Bob Marley - 03 - Simmer Down.mp3")); Assert.IsTrue(playlist[3].FileName.EndsWith("Bob Marley - 05 - Guava Jelly.mp3")); }
/// <summary> /// Does the play. /// </summary> /// <param name="item">The item.</param> public void DoPlay(RadioTimeOutline item) { ShowWaitCursor(); try { _station = null; _nowPlaying = null; _show = null; _currentItem = null; if (item == null || string.IsNullOrEmpty(item.GuidId)) { ErrMessage(Translation.StationNotAvaiable); return; } PlayGuidId = item.GuidId ; _currentItem = item.Clone(); //RadioTimeStation station = Settings.NowPlayingStation; _station = new RadioTimeStation(); _station.Grabber = grabber; _station.Get(PlayGuidId); if (_station.IsAvailable) { //var nowPlaying = Settings.NowPlaying; _nowPlaying = new RadioTimeNowPlaying(); _nowPlaying.Grabber = grabber; _nowPlaying.Get(PlayGuidId, _station.HasSong); if (_nowPlaying.IsShow && !string.IsNullOrEmpty(_nowPlaying.ShowGuidId)) { _show = new RadioTimeShow(); _show.Grabber = grabber; _show.Get(_nowPlaying.ShowGuidId) ; } var playerType = PlayerType.Video; if (_setting.FormatPlayer.ContainsKey(item.Formats)) playerType = _setting.FormatPlayer[item.Formats]; try { var playList = new PlayList(); //if (item.Url.ToLower().Contains(".pls") || item.Url.ToLower().Contains(".m3u") || item.Url.ToLower().Contains(".asx")) { var TargetFile = Path.GetTempFileName(); var client = new WebClient(); try { if (item.Url.ToLower().Contains(".pls")) { client.DownloadFile(item.Url, TargetFile); IPlayListIO loader = new PlayListPLSEIO(); loader.Load(playList, TargetFile); } else if (item.Url.ToLower().Contains(".asx")) { client.DownloadFile(item.Url, TargetFile); IPlayListIO loader = new PlayListASXIO(); loader.Load(playList, TargetFile); } else { client.DownloadFile(item.Url, TargetFile); IPlayListIO loader = new PlayListM3uIO(); loader.Load(playList, TargetFile); } } finally { client.Dispose(); File.Delete(TargetFile); } //if (playList.Count > 0 && playList[0].FileName.ToLower().StartsWith("http") && playList[0].FileName.ToLower().Contains(".m3u")) //{ // client.DownloadFile(playList[0].FileName, TargetFile); // IPlayListIO loader1 = new PlayListM3uIO(); // loader1.Load(playList, TargetFile); // File.Delete(TargetFile); //} TargetFile = Path.GetTempFileName(); client = new WebClient(); try { if (playList.Count > 0 && playList[0].FileName.ToLower().Contains(".pls")) { client.DownloadFile(playList[0].FileName, TargetFile); IPlayListIO loader1 = new PlayListPLSEIO(); loader1.Load(playList, TargetFile); } if (playList.Count > 0 && playList[0].FileName.ToLower().Contains(".asx")) { client.DownloadFile(playList[0].FileName, TargetFile); IPlayListIO loader1 = new PlayListASXIO(); loader1.Load(playList, TargetFile); } if (playList.Count > 0 && playList[0].FileName.ToLower().Contains(".m3u")) { client.DownloadFile(playList[0].FileName, TargetFile); IPlayListIO loader1 = new PlayListM3uIO(); loader1.Load(playList, TargetFile); if (playList.Count == 0) { IPlayListIO loader2 = new PlayListPLSEIO(); loader2.Load(playList, TargetFile); } } } finally { client.Dispose(); File.Delete(TargetFile); } } if (playList.Count > 0) _currentFileName = playList[0].FileName; else _currentFileName = item.Url; switch (playerType) { case PlayerType.Audio: ClearPlayProps(); g_Player.PlayAudioStream(_currentFileName); return; case PlayerType.Video: // test if the station have tv group ClearPlayProps(); if (item.GenreId == "g260" || item.GenreId == "g83" || item.GenreId == "g374" || item.GenreId == "g2769") g_Player.PlayVideoStream(_currentFileName); else g_Player.Play(_currentFileName, g_Player.MediaType.Unknown); return; case PlayerType.Unknow: return; default: return; } // moved to PLAYBACKSTARTED EVENT //if (isPlaying && g_Player.CurrentFile == playList[0].FileName) } catch (Exception exception) { _currentItem = null; ErrMessage(string.Format(Translation.PlayError, exception.Message)); return; } } } finally { HideWaitCursor(); } ErrMessage(Translation.StationNotAvaiable); return; }
/// <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); } } } }