Пример #1
0
    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"));
    }
Пример #2
0
    private void SavePlayList()
    {
      string strNewFileName = playlistPlayer.CurrentPlaylistName;
      if (GetKeyboard(ref strNewFileName))
      {
        string strPath = Path.GetFileNameWithoutExtension(strNewFileName);
        string strPlayListPath = string.Empty;
        using (Profile.Settings xmlreader = new Profile.MPSettings())
        {
          strPlayListPath = xmlreader.GetValueAsString("music", "playlists", string.Empty);
          strPlayListPath = Util.Utils.RemoveTrailingSlash(strPlayListPath);
        }

        strPath += ".m3u";
        if (strPlayListPath.Length != 0)
        {
          strPath = strPlayListPath + @"\" + strPath;
        }
        PlayList playlist = new PlayList();
        for (int i = 0; i < facadeLayout.Count; ++i)
        {
          GUIListItem pItem = facadeLayout[i];
          PlayListItem newItem = new PlayListItem();
          newItem.FileName = pItem.Path;
          newItem.Description = pItem.Label;
          newItem.Duration = pItem.Duration;
          newItem.Type = PlayListItem.PlayListItemType.Audio;
          playlist.Add(newItem);
        }
        IPlayListIO saver = new PlayListM3uIO();
        saver.Save(playlist, strPath);
      }
    }
Пример #3
0
    public override void DeInit()
    {
      GUIWindowManager.Receivers -= new SendMessageHandler(this.OnThreadMessage);
      GUIWindowManager.OnNewAction -= new OnActionHandler(this.OnNewAction);

      if (_lastRequest != null)
      {
        ascrobbler.RemoveRequest(_lastRequest);
      }

      // Save the default Playlist
      if (_savePlaylistOnExit)
      {
          Log.Info("Playlist: Saving default playlist {0}", _defaultPlaylist);
          IPlayListIO saver = new PlayListM3uIO();
          PlayList playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC);
          PlayList playlistTmp = new PlayList();
          // Sort out Playlist Items residing on a CD, as they are gonna most likely to change
          foreach (PlayListItem item in playlist)
          {
              if (Path.GetExtension(item.FileName) != ".cda")
              {
                  playlistTmp.Add(item);
              }
          }

          if (playlistTmp.Count > 0)
          {
              saver.Save(playlistTmp, Path.Combine(_playlistFolder, _defaultPlaylist));
          }
      }

      base.DeInit();
    }
Пример #4
0
        /// <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;
        }
    private void OnSavePlayList()
    {
      currentSelectedItem = facadeLayout.SelectedListItemIndex;
      string playlistFileName = string.Empty;
      if (GetKeyboard(ref playlistFileName))
      {
        string playListPath = string.Empty;
        using (Profile.Settings xmlreader = new Profile.MPSettings())
        {
          playListPath = xmlreader.GetValueAsString("movies", "playlists", string.Empty);
          playListPath = Util.Utils.RemoveTrailingSlash(playListPath);
        }

        string fullPlayListPath = Path.GetFileNameWithoutExtension(playlistFileName);

        fullPlayListPath += ".m3u";
        if (playListPath.Length != 0)
        {
          fullPlayListPath = playListPath + @"\" + fullPlayListPath;
        }
        PlayList playlist = new PlayList();
        for (int i = 0; i < facadeLayout.Count; ++i)
        {
          GUIListItem listItem = facadeLayout[i];
          PlayListItem playListItem = new PlayListItem();
          playListItem.FileName = listItem.Path;
          playListItem.Description = listItem.Label;
          playListItem.Duration = listItem.Duration;
          playListItem.Type = PlayListItem.PlayListItemType.Video;
          playlist.Add(playListItem);
        }
        PlayListM3uIO saver = new PlayListM3uIO();
        saver.Save(playlist, fullPlayListPath);
      }
    }
Пример #6
0
        /// <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);
            }
        }
Пример #7
0
        /// <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);
                    }
                }
            }
        }