public string Get(int iSong)
        {
            if (_currentPlayList == PlayListType.PLAYLIST_NONE)
            {
                return(string.Empty);
            }

            PlayList playlist = GetPlaylist(_currentPlayList);

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

            if (iSong >= playlist.Count)
            {
                //	Is last element of video stacking playlist?
                if (_currentPlayList == PlayListType.PLAYLIST_VIDEO_TEMP)
                {
                    return(string.Empty);
                }

                if (!_repeatPlayList)
                {
                    return(string.Empty);

                    ;
                }
                iSong = 0;
            }

            PlayListItem item = playlist[iSong];

            return(item.FileName);
        }
Example #2
0
    public bool Load(PlayList playlist, string fileName)
    {
      playlist.Clear();
      XmlNodeList nodeEntries;

      if (!LoadXml(fileName, out nodeEntries))
        return false;

      try
      {
        string basePath = Path.GetDirectoryName(Path.GetFullPath(fileName));
        foreach (XmlNode node in nodeEntries)
        {
          string file = ReadFileName(node);

          if (file == null)
            return false;

          string infoLine = ReadInfoLine(node, file);
          int duration = ReadLength(node);

          SetupTv.Utils.GetQualifiedFilename(basePath, ref file);
          PlayListItem newItem = new PlayListItem(infoLine, file, duration);
          playlist.Add(newItem);
        }
        return true;
      }
      catch (Exception)
      {
        return false;
      }
    }
Example #3
0
        private bool AddItem(string songName, int duration, string fileName)
        {
            if (fileName == null || fileName.Length == 0)
            {
                return(false);
            }

            PlayListItem newItem = new PlayListItem(songName, fileName, duration);

            if (fileName.ToLower().StartsWith("http:") || fileName.ToLower().StartsWith("https:") ||
                fileName.ToLower().StartsWith("mms:") || fileName.ToLower().StartsWith("rtp:"))
            {
                newItem.Type = PlayListItem.PlayListItemType.AudioStream;
            }
            else
            {
                Util.Utils.GetQualifiedFilename(basePath, ref fileName);
                newItem.FileName = fileName;
                newItem.Type     = PlayListItem.PlayListItemType.Audio;
            }
            if (songName.Length == 0)
            {
                newItem.Description = Path.GetFileName(fileName);
            }
            playlist.Add(newItem);
            return(true);
        }
Example #4
0
        /// <summary>
        /// Create playlist item from a file
        /// </summary>
        /// <param name="file">Path to file</param>
        /// <returns>Playlist item</returns>
        internal static MediaPortal.Playlists.PlayListItem CreatePlaylistItemFromMusicFile(string file)
        {
            FileInfo info = null;

            MediaPortal.Playlists.PlayListItem item = new MediaPortal.Playlists.PlayListItem();

            try
            {
                info = new FileInfo(file);
            }
            catch (Exception e)
            {
                WifiRemote.LogMessage("Error loading music item from file: " + e.Message, WifiRemote.LogType.Error);
            }

            if (info != null)
            {
                item.Description = info.Name;
                item.FileName    = info.FullName;
                item.Type        = PlayListItem.PlayListItemType.Audio;
                MusicDatabase mpMusicDb = MusicDatabase.Instance;
                Song          song      = new Song();
                bool          inDb      = mpMusicDb.GetSongByFileName(item.FileName, ref song);

                if (inDb)
                {
                    item.Duration = song.Duration;
                }
            }

            return(item);
        }
Example #5
0
 public bool Save(PlayList playlist, string fileName)
 {
     try
     {
         using (StreamWriter writer = new StreamWriter(fileName, false, Encoding.UTF8))
         {
             writer.WriteLine(START_PLAYLIST_MARKER);
             for (int i = 0; i < playlist.Count; i++)
             {
                 PlayListItem item = playlist[i];
                 writer.WriteLine("File{0}={1}", i + 1, item.FileName);
                 writer.WriteLine("Title{0}={1}", i + 1, item.Description);
                 writer.WriteLine("Length{0}={1}", i + 1, item.Duration);
             }
             writer.WriteLine("NumberOfEntries={0}", playlist.Count);
             writer.WriteLine("Version=2");
         }
         return(true);
     }
     catch (Exception e)
     {
         Log.Info("failed to save a playlist {0}. err: {1} stack: {2}", fileName, e.Message, e.StackTrace);
         return(false);
     }
 }
Example #6
0
    public void NewlyAddedSongsAreNotMarkedPlayed()
    {
      PlayList pl = new PlayList();
      PlayListItem item = new PlayListItem("my song", "myfile.mp3");
      pl.Add(item);

      Assert.IsFalse(pl.AllPlayed());
    }
Example #7
0
 public void Add(PlayListItem item)
 {
     _playlist.Add(item);
     GUIListItem guiItem = new GUIListItem();
     guiItem.Label = item.Description;
     _playlistDic.Add(guiItem, item);
     playlistControl.Add(guiItem);
 }
 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());
 }
Example #10
0
    public void RemoveReallyRemovesASong()
    {
      PlayList pl = new PlayList();
      PlayListItem item = new PlayListItem("my song", "myfile.mp3");
      pl.Add(item);

      pl.Remove("myfile.mp3");

      Assert.AreEqual(0, pl.Count);
    }
 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);
 }
Example #12
0
    public void AllPlayedReturnsTrueWhenAllArePlayed()
    {
      PlayList pl = new PlayList();
      PlayListItem item = new PlayListItem("my song", "myfile.mp3");
      item.Played = true;
      pl.Add(item);

      item = new PlayListItem("my 2:d song", "myfile2.mp3");
      item.Played = true;
      pl.Add(item);

      Assert.IsTrue(pl.AllPlayed());
    }
        public string GetNext()
        {
            PlayListItem resultingItem = GetNextItem();

            if (resultingItem != null)
            {
                return(resultingItem.FileName);
            }
            else
            {
                return(string.Empty);
            }
        }
Example #14
0
        public bool Load(PlayList playlist, string fileName)
        {
            playlist.Clear();

              try
              {
            string basePath = Path.GetDirectoryName(Path.GetFullPath(fileName));
            XmlDocument doc = new XmlDocument();
            doc.Load(fileName);
            if (doc.DocumentElement == null)
            {
              return false;
            }
            XmlNode nodeRoot = doc.DocumentElement.SelectSingleNode("/asx");
            if (nodeRoot == null)
            {
              return false;
            }
            XmlNodeList nodeEntries = nodeRoot.SelectNodes("entry");
            foreach (XmlNode node in nodeEntries)
            {
              XmlNode srcNode = node.SelectSingleNode("ref");
              if (srcNode != null)
              {
            XmlNode url = srcNode.Attributes.GetNamedItem("href");
            if (url != null)
            {
              if (url.InnerText != null)
              {
                if (url.InnerText.Length > 0)
                {
                  fileName = url.InnerText;
                  if (!(fileName.ToLowerInvariant().StartsWith("http") || fileName.ToLowerInvariant().StartsWith("mms") || fileName.ToLowerInvariant().StartsWith("rtp")))
                    continue;

                  PlayListItem newItem = new PlayListItem(fileName, fileName, 0);
                  newItem.Type = PlayListItem.PlayListItemType.Audio;
                  playlist.Add(newItem);
                }
              }
            }
              }
            }
            return true;
              }
              catch (Exception ex)
              {
            Log.Info("exception loading playlist {0} err:{1} stack:{2}", fileName, ex.Message, ex.StackTrace);
              }
              return false;
        }
Example #15
0
        public bool Load(PlayList playlist, string playlistFileName)
        {
            playlist.Clear();

            try
            {
                var doc = new XmlDocument();
                doc.Load(playlistFileName);
                if (doc.DocumentElement == null)
                {
                    return(false);
                }
                XmlNode nodeRoot = doc.DocumentElement.SelectSingleNode("/smil/body/seq");
                if (nodeRoot == null)
                {
                    return(false);
                }
                XmlNodeList nodeEntries = nodeRoot.SelectNodes("media");
                if (nodeEntries != null)
                {
                    foreach (XmlNode node in nodeEntries)
                    {
                        XmlNode srcNode = node.Attributes.GetNamedItem("src");
                        if (srcNode != null)
                        {
                            if (srcNode.InnerText != null)
                            {
                                if (srcNode.InnerText.Length > 0)
                                {
                                    var playlistUrl = srcNode.InnerText;
                                    var newItem     = new PlayListItem(playlistUrl, playlistUrl, 0)
                                    {
                                        Type = PlayListItem.PlayListItemType.Audio
                                    };
                                    string description = Path.GetFileName(playlistUrl);
                                    newItem.Description = description;
                                    playlist.Add(newItem);
                                }
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                Log.Error(e.StackTrace);
            }
            return(false);
        }
Example #16
0
        public bool Load(PlayList playlist, string fileName)
        {
            playlist.Clear();

            try
            {
                string      basePath = Path.GetDirectoryName(Path.GetFullPath(fileName));
                XmlDocument doc      = new XmlDocument();
                doc.Load(fileName);
                if (doc.DocumentElement == null)
                {
                    return(false);
                }
                XmlNode nodeRoot = doc.DocumentElement.SelectSingleNode("/smil/body/seq");
                if (nodeRoot == null)
                {
                    return(false);
                }
                XmlNodeList nodeEntries = nodeRoot.SelectNodes("media");
                foreach (XmlNode node in nodeEntries)
                {
                    XmlNode srcNode = node.Attributes.GetNamedItem("src");
                    if (srcNode != null)
                    {
                        if (srcNode.InnerText != null)
                        {
                            if (srcNode.InnerText.Length > 0)
                            {
                                fileName = srcNode.InnerText;
                                Util.Utils.GetQualifiedFilename(basePath, ref fileName);
                                PlayListItem newItem = new PlayListItem(fileName, fileName, 0);
                                newItem.Type = PlayListItem.PlayListItemType.Audio;
                                string description;
                                description         = Path.GetFileName(fileName);
                                newItem.Description = description;
                                playlist.Add(newItem);
                            }
                        }
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Log.Info("exception loading playlist {0} err:{1} stack:{2}", fileName, ex.Message, ex.StackTrace);
            }
            return(false);
        }
Example #17
0
    public bool Load(PlayList playlist, string fileName)
    {
      playlist.Clear();

      try
      {
        string basePath = Path.GetDirectoryName(Path.GetFullPath(fileName));
        XmlDocument doc = new XmlDocument();
        doc.Load(fileName);
        if (doc.DocumentElement == null)
        {
          return false;
        }
        XmlNode nodeRoot = doc.DocumentElement.SelectSingleNode("/smil/body/seq");
        if (nodeRoot == null)
        {
          return false;
        }
        XmlNodeList nodeEntries = nodeRoot.SelectNodes("media");
        foreach (XmlNode node in nodeEntries)
        {
          XmlNode srcNode = node.Attributes.GetNamedItem("src");
          if (srcNode != null)
          {
            if (srcNode.InnerText != null)
            {
              if (srcNode.InnerText.Length > 0)
              {
                fileName = srcNode.InnerText;
                Util.Utils.GetQualifiedFilename(basePath, ref fileName);
                PlayListItem newItem = new PlayListItem(fileName, fileName, 0);
                newItem.Type = PlayListItem.PlayListItemType.Audio;
                string description;
                description = Path.GetFileName(fileName);
                newItem.Description = description;
                playlist.Add(newItem);
              }
            }
          }
        }
        return true;
      }
      catch (Exception ex)
      {
        Log.Info("exception loading playlist {0} err:{1} stack:{2}", fileName, ex.Message, ex.StackTrace);
      }
      return false;
    }
Example #18
0
 public void Save(PlayList playlist, string fileName)
 {
     using (StreamWriter writer = new StreamWriter(fileName, false, Encoding.UTF8))
     {
         writer.WriteLine(START_PLAYLIST_MARKER);
         for (int i = 0; i < playlist.Count; i++)
         {
             PlayListItem item = playlist[i];
             writer.WriteLine("File{0}={1}", i + 1, item.FileName);
             writer.WriteLine("Title{0}={1}", i + 1, item.Description);
             writer.WriteLine("Length{0}={1}", i + 1, item.Duration);
         }
         writer.WriteLine("NumberOfEntries={0}", playlist.Count);
         writer.WriteLine("Version=2");
     }
 }
Example #19
0
        /// <summary>
        /// Add MpExtended information to playlist item
        /// </summary>
        /// <param name="item">MediaPortal playlist item</param>
        /// <param name="message">Playlist message item that is sent to client</param>
        internal static void AddMpExtendedInfo(MediaPortal.Playlists.PlayListItem item, PlaylistEntry message)
        {
            MusicDatabase mpMusicDb = MusicDatabase.Instance;
            Song          song      = new Song();
            bool          inDb      = mpMusicDb.GetSongByFileName(item.FileName, ref song);

            if (inDb)
            {
                message.Name2           = song.Album;
                message.AlbumArtist     = song.AlbumArtist;
                message.Title           = song.Title;
                message.MpExtId         = song.Id.ToString();
                message.MpExtMediaType  = (int)MpExtended.MpExtendedMediaTypes.MusicTrack;
                message.MpExtProviderId = (int)MpExtended.MpExtendedProviders.MPMusic;
            }
        }
Example #20
0
    public void ResetSetsAllItemsToFalse()
    {
      PlayList pl = new PlayList();
      PlayListItem item = new PlayListItem("my song", "myfile.mp3");
      pl.Add(item);

      PlayListItem item2 = new PlayListItem("my 2:d song", "myfile2.mp3");
      pl.Add(item2);

      pl[0].Played = true;
      pl[1].Played = true;

      pl.ResetStatus();

      Assert.IsFalse(pl[0].Played);
      Assert.IsFalse(pl[1].Played);
    }
Example #21
0
        /// <summary>
        /// Create playlist item from a file
        /// </summary>
        /// <param name="file">Path to file</param>
        /// <returns>Playlist item</returns>
        internal static MediaPortal.Playlists.PlayListItem CreatePlaylistItemFromVideoFile(string file)
        {
            FileInfo info = new FileInfo(file);
            MediaPortal.Playlists.PlayListItem item = new MediaPortal.Playlists.PlayListItem();
            item.Description = info.Name;
            item.FileName = info.FullName;
            item.Type = PlayListItem.PlayListItemType.Video;
            //item.Duration
            IMDBMovie movie = new IMDBMovie();
            int id = VideoDatabase.GetMovieInfo(file, ref movie);

            if (id > 0)
            {
                item.Duration = movie.RunTime;
            }

            return item;
        }
        public string GetNextSong()
        {
            PlayListItem item = GetNextItem();

            if (item == null)
            {
                return(string.Empty);
            }

            _currentItem++;

            GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_ITEM_FOCUS, 0, 0, 0, _currentItem, 0, null);

            msg.Label = item.FileName;
            GUIGraphicsContext.SendMessage(msg);

            return(item.FileName);
        }
Example #23
0
    public bool Load(PlayList playlist, string playlistFileName)
    {
      playlist.Clear();

      try
      {
        var doc = new XmlDocument();
        doc.Load(playlistFileName);
        if (doc.DocumentElement == null)
          return false;
        XmlNode nodeRoot = doc.DocumentElement.SelectSingleNode("/smil/body/seq");
        if (nodeRoot == null)
          return false;
        XmlNodeList nodeEntries = nodeRoot.SelectNodes("media");
        if (nodeEntries != null)
          foreach (XmlNode node in nodeEntries)
          {
            XmlNode srcNode = node.Attributes.GetNamedItem("src");
            if (srcNode != null)
            {
              if (srcNode.InnerText != null)
              {
                if (srcNode.InnerText.Length > 0)
                {
                  var playlistUrl = srcNode.InnerText;
                  var newItem = new PlayListItem(playlistUrl, playlistUrl, 0)
                                  {
                                    Type = PlayListItem.PlayListItemType.Audio
                                  };
                  string description = Path.GetFileName(playlistUrl);
                  newItem.Description = description;
                  playlist.Add(newItem);
                }
              }
            }
          }
        return true;
      }
      catch (Exception e)
      {
        Log.Error(e.StackTrace);
      }
      return false;
    }
Example #24
0
        /// <summary>
        /// Create playlist item from a file
        /// </summary>
        /// <param name="file">Path to file</param>
        /// <returns>Playlist item</returns>
        internal static MediaPortal.Playlists.PlayListItem CreatePlaylistItemFromVideoFile(string file)
        {
            FileInfo info = new FileInfo(file);

            MediaPortal.Playlists.PlayListItem item = new MediaPortal.Playlists.PlayListItem();
            item.Description = info.Name;
            item.FileName    = info.FullName;
            item.Type        = PlayListItem.PlayListItemType.Video;
            //item.Duration
            IMDBMovie movie = new IMDBMovie();
            int       id    = VideoDatabase.GetMovieInfo(file, ref movie);

            if (id > 0)
            {
                item.Duration = movie.RunTime;
            }

            return(item);
        }
        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;
                }
            }
        }
Example #26
0
        public bool Load(PlayList playlist, string fileName)
        {
            playlist.Clear();
            XmlNodeList nodeEntries;

            if (!LoadXml(fileName, out nodeEntries))
            {
                return(false);
            }

            try
            {
                string basePath = Path.GetDirectoryName(Path.GetFullPath(fileName));
                foreach (XmlNode node in nodeEntries)
                {
                    string file = ReadFileName(node);

                    if (file == null)
                    {
                        return(false);
                    }

                    string infoLine = ReadInfoLine(node, file);
                    int    duration = ReadLength(node);

                    file = PathUtil.GetAbsolutePath(basePath, file);
                    PlayListItem newItem = new PlayListItem(infoLine, file, duration);
                    playlist.Add(newItem);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Log.Info("exception loading playlist {0} err:{1} stack:{2}", fileName, ex.Message, ex.StackTrace);
                return(false);
            }
        }
Example #27
0
        public bool Load(PlayList playlist, string fileName)
        {
            playlist.Clear();
            XmlNodeList nodeEntries;

            if (!LoadXml(fileName, out nodeEntries))
            {
                return false;
            }

            try
            {
                string basePath = Path.GetDirectoryName(Path.GetFullPath(fileName));
                foreach (XmlNode node in nodeEntries)
                {
                    string file = ReadFileName(node);

                    if (file == null)
                    {
                        return false;
                    }

                    string infoLine = ReadInfoLine(node, file);
                    int duration = ReadLength(node);

                    file = PathUtil.GetAbsolutePath(basePath, file);
                    PlayListItem newItem = new PlayListItem(infoLine, file, duration);
                    playlist.Add(newItem);
                }
                return true;
            }
            catch (Exception ex)
            {
                Log.Info("exception loading playlist {0} err:{1} stack:{2}", fileName, ex.Message, ex.StackTrace);
                return false;
            }
        }
        public PlayListItem GetNextItem()
        {
            if (_currentPlayList == PlayListType.PLAYLIST_NONE)
            {
                return(null);
            }

            PlayList playlist = GetPlaylist(_currentPlayList);

            if (playlist.Count <= 0)
            {
                return(null);
            }
            int iSong = _currentItem;

            iSong++;

            if (iSong >= playlist.Count)
            {
                //	Is last element of video stacking playlist?
                if (_currentPlayList == PlayListType.PLAYLIST_VIDEO_TEMP)
                {
                    return(null);
                }

                if (!_repeatPlayList)
                {
                    return(null);
                }

                iSong = 0;
            }

            PlayListItem item = playlist[iSong];

            return(item);
        }
Example #29
0
        public bool Load(PlayList playlist, string fileName)
        {
            playlist.Clear();
            XmlNodeList nodeEntries;

            if (!LoadXml(fileName, out nodeEntries))
            {
                return(false);
            }

            try
            {
                string basePath = Path.GetDirectoryName(Path.GetFullPath(fileName));
                foreach (XmlNode node in nodeEntries)
                {
                    string file = ReadFileName(node);

                    if (file == null)
                    {
                        return(false);
                    }

                    string infoLine = ReadInfoLine(node, file);
                    int    duration = ReadLength(node);

                    Utils.GetQualifiedFilename(basePath, ref file);
                    PlayListItem newItem = new PlayListItem(infoLine, file, duration);
                    playlist.Add(newItem);
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
    protected void OnPlayFiles(System.Collections.ArrayList filesList)
    {
      playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO_TEMP).Clear();
      playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO).Clear();

      foreach (string file in filesList)
      {
        PlayListItem item = new PlayListItem();
        item.FileName = file;
        item.Type = PlayListItem.PlayListItemType.Video;
        item.Description = file;
        playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO).Add(item);
      }

      if (playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO).Count > 0)
      {
        GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_VIDEO_PLAYLIST);
        playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_VIDEO;
        playlistPlayer.Reset();
        playlistPlayer.Play(0);
      }
    }
 protected virtual void AddItemToPlayList(GUIListItem pItem)
 {
   if (!pItem.IsFolder)
   {
     //TODO
     if (Util.Utils.IsVideo(pItem.Path) && !PlayListFactory.IsPlayList(pItem.Path))
     {
       PlayListItem playlistItem = new PlayListItem();
       playlistItem.Type = PlayListItem.PlayListItemType.Video;
       playlistItem.FileName = pItem.Path;
       playlistItem.Description = pItem.Label;
       playlistItem.Duration = pItem.Duration;
       playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO).Add(playlistItem);
     }
   }
 }
        void player_PlayBegin(YoutubePlaylistPlayer playlit, PlayListItem item)
        {
            try
              {
            //ClearLabels("NowPlaying");
            VideoInfo info = item.MusicTag as VideoInfo;
            if (info == null)
              return;

            Log.Debug("YouTube.fm playback started");
            YouTubeEntry en = info.Entry;

            if (en.Authors.Count == 0)
            {
              Uri videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + Youtube2MP.GetVideoId(en));
              try
              {
            Video video = Youtube2MP.request.Retrieve<Video>(videoEntryUrl);
            en = video.YouTubeEntry;
              }
              catch (Exception)
              {
            //vid = null;
              }
            }

            en.Title.Text = item.Description;
            item.FileName = Youtube2MP.StreamPlaybackUrl(en, info);
            ClearLabels("NowPlaying",true);
            ClearLabels("Next", true);
            Youtube2MP.NowPlayingEntry = en;
            Youtube2MP.NextPlayingEntry = null;
            //ArtistManager.Instance.SetSkinProperties(Youtube2MP.NextPlayingEntry, "NowPlaying", false, false);
            if (playlit.GetNextItem() != null)
            {
              VideoInfo nextinfo = playlit.GetNextItem().MusicTag as VideoInfo;
              if (nextinfo != null)
              {
            Youtube2MP.NextPlayingEntry = nextinfo.Entry;
            //ArtistManager.Instance.SetSkinProperties(Youtube2MP.NextPlayingEntry, "Next", false, false);
              }
            }
            BackgroundWorker playBeginWorker = new BackgroundWorker();
            playBeginWorker.DoWork += playBeginWorker_DoWork;
            playBeginWorker.RunWorkerAsync();
            Youtube2MP.YouTubePlaying = true;
            GUIPropertyManager.SetProperty("#Youtube.fm.FullScreen.ShowTitle", "true");
            GUIPropertyManager.SetProperty("#Youtube.fm.FullScreen.ShowNextTitle",
                                       Youtube2MP.NextPlayingEntry != null ? "true" : "false");
            _labelTimer.Stop();
            _labelTimer.Start();
              }
              catch (Exception exception)
              {
            Log.Error("Youtube play begin exception");
            Log.Error(exception);
              }
        }
Example #33
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);
      }
    }
Example #34
0
    private bool AddRandomSongToPlaylist(ref Song song)
    {
      //check duplication
      PlayList playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC);
      for (int i = 0; i < playlist.Count; i++)
      {
        PlayListItem item = playlist[i];
        if (item.FileName == song.FileName)
        {
          return false;
        }
      }

      //add to playlist
      PlayListItem playlistItem = new PlayListItem();
      playlistItem.Type = PlayListItem.PlayListItemType.Audio;
      StringBuilder sb = new StringBuilder();

      playlistItem.FileName = song.FileName;
      sb.Append(song.Track);
      sb.Append(". ");
      sb.Append(song.Artist);
      sb.Append(" - ");
      sb.Append(song.Title);
      playlistItem.Description = sb.ToString();
      playlistItem.Duration = song.Duration;

      MusicTag tag = new MusicTag();
      tag = song.ToMusicTag();

      playlistItem.MusicTag = tag;

      playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC).Add(playlistItem);
      return true;
    }
Example #35
0
    private void AddToPlayList(PlayList tmpPlayList, IEnumerable<object> sortedPlayList)
    {
      foreach (string file in sortedPlayList)
      {
        // Remove stop data if exists
        int idFile = VideoDatabase.GetFileId(file);

        if (idFile >= 0)
        {
          VideoDatabase.DeleteMovieStopTime(idFile);
        }

        // Add file to tmp playlist
        PlayListItem newItem = new PlayListItem();
        newItem.FileName = file;
        // Set file description (for sorting by name -> DVD IFO file problem)
        string description = string.Empty;

        if (file.ToUpperInvariant().IndexOf(@"\VIDEO_TS\VIDEO_TS.IFO", StringComparison.InvariantCultureIgnoreCase) >= 0)
        {
          string dvdFolder = file.Substring(0, file.ToUpperInvariant().IndexOf(@"\VIDEO_TS\VIDEO_TS.IFO", StringComparison.InvariantCultureIgnoreCase));
          description = Path.GetFileName(dvdFolder);
        }
        if (file.ToUpperInvariant().IndexOf(@"\BDMV\INDEX.BDMV", StringComparison.InvariantCultureIgnoreCase) >= 0)
        {
          string bdFolder = file.Substring(0, file.ToUpperInvariant().IndexOf(@"\BDMV\INDEX.BDMV", StringComparison.InvariantCultureIgnoreCase));
          description = Path.GetFileName(bdFolder);
        }
        else
        {
          description = Path.GetFileName(file);
        }

        newItem.Description = description;
        newItem.Type = PlayListItem.PlayListItemType.Video;
        tmpPlayList.Add(newItem);
      }
    }
    private void StartBackgroundMusic(string path)
    {
      if (g_Player.IsMusic || g_Player.IsRadio || g_Player.IsTV || g_Player.IsVideo)
      {
        return;
      }

      // Load Music related settings here, as the Loadsetting for pictures is called too late for the Backgroundmusic task
      using (Profile.Settings reader = new Profile.MPSettings())
      {
        _musicFileExtensions = reader.GetValueAsString("music", "extensions", ".mp3,.pls,.wpl").Split(',');
        _autoShuffleMusic = reader.GetValueAsBool("musicfiles", "autoshuffle", false);
      }

      foreach (string extension in _musicFileExtensions)
      {
        string filename = string.Format(@"{0}\Folder{1}", path, extension);

        if (File.Exists(filename) == false)
        {
          continue;
        }

        try
        {
          PlayList playlist = playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC_TEMP);
          playlist.Clear();
          playlistPlayer.Reset();
          playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_MUSIC_TEMP;

          // Check, if we got a playlist to allow shuffle
          if (Util.Utils.IsPlayList(filename))
          {
            IPlayListIO loader = PlayListFactory.CreateIO(filename);
            if (loader == null)
            {
              return;
            }

            if (!loader.Load(playlist, filename))
            {
              return;
            }

            if (_autoShuffleMusic)
            {
              Random r = new Random((int)DateTime.Now.Ticks);
              int shuffleCount = r.Next() % 50;
              for (int i = 0; i < shuffleCount; ++i)
              {
                playlist.Shuffle();
              }
            }
          }
          else
          {
            PlayListItem playlistItem = new PlayListItem();

            playlistItem.Type = PlayListItem.PlayListItemType.Audio;
            playlistItem.FileName = filename;
            playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC_TEMP).Add(playlistItem);
          }
          playlistPlayer.Play(0);

          _isBackgroundMusicPlaying = true;
        }
        catch (Exception e)
        {
          Log.Info("GUISlideShow.StartBackgroundMusic", e.Message);
        }

        break;
      }
    }
Example #37
0
    public PlayListItem ToPlayListItem()
    {
      var pli = new PlayListItem
                  {
                    Type = PlayListItem.PlayListItemType.Audio,
                    FileName = this.FileName,
                    Description = this.Title,
                    Duration = this.Duration
                  };

      MusicTag tag = this.ToMusicTag();
      pli.MusicTag = tag;

      return pli;
    }
Example #38
0
        public bool Load(PlayList playlist, string fileName)
        {
            string extension = Path.GetExtension(fileName);

            extension.ToLowerInvariant();

            playlist.Clear();
            playlist.Name = Path.GetFileName(fileName);
            string       basePath     = Path.GetDirectoryName(Path.GetFullPath(fileName));
            Encoding     fileEncoding = Encoding.Default;
            FileStream   stream       = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            StreamReader file         = new StreamReader(stream, fileEncoding, true);

            string line = file.ReadLine();

            if (line == null)
            {
                file.Close();
                return(false);
            }

            string strLine = line.Trim();

            //CUtil::RemoveCRLF(strLine);
            if (strLine != START_PLAYLIST_MARKER)
            {
                if (strLine.StartsWith("http") || strLine.StartsWith("HTTP") ||
                    strLine.StartsWith("mms") || strLine.StartsWith("MMS") ||
                    strLine.StartsWith("rtp") || strLine.StartsWith("RTP"))
                {
                    PlayListItem newItem = new PlayListItem(strLine, strLine, 0);
                    newItem.Type = PlayListItem.PlayListItemType.AudioStream;
                    playlist.Add(newItem);
                    file.Close();
                    return(true);
                }
                fileEncoding = Encoding.Default; // No unicode??? rtv
                stream       = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                file         = new StreamReader(stream, fileEncoding, true);

                //file.Close();
                //return false;
            }
            string infoLine     = "";
            string durationLine = "";

            fileName = "";
            line     = file.ReadLine();
            while (line != null)
            {
                strLine = line.Trim();
                //CUtil::RemoveCRLF(strLine);
                int equalPos = strLine.IndexOf("=");
                if (equalPos > 0)
                {
                    string leftPart = strLine.Substring(0, equalPos);
                    equalPos++;
                    string valuePart = strLine.Substring(equalPos);
                    leftPart = leftPart.ToLowerInvariant();
                    if (leftPart.StartsWith("file"))
                    {
                        if (valuePart.Length > 0 && valuePart[0] == '#')
                        {
                            line = file.ReadLine();
                            continue;
                        }

                        if (fileName.Length != 0)
                        {
                            PlayListItem newItem = new PlayListItem(infoLine, fileName, 0);
                            playlist.Add(newItem);
                            infoLine     = "";
                            durationLine = "";
                        }
                        fileName = valuePart;
                    }
                    if (leftPart.StartsWith("title"))
                    {
                        infoLine = valuePart;
                    }
                    else
                    {
                        if (infoLine == "")
                        {
                            infoLine = Path.GetFileName(fileName);
                        }
                    }
                    if (leftPart.StartsWith("length"))
                    {
                        durationLine = valuePart;
                    }
                    if (leftPart == "playlistname")
                    {
                        playlist.Name = valuePart;
                    }

                    if (durationLine.Length > 0 && infoLine.Length > 0 && fileName.Length > 0)
                    {
                        int duration = System.Int32.Parse(durationLine);
                        duration *= 1000;

                        string       tmp     = fileName.ToLowerInvariant();
                        PlayListItem newItem = new PlayListItem(infoLine, fileName, duration);
                        if (tmp.IndexOf("http:") < 0 && tmp.IndexOf("mms:") < 0 && tmp.IndexOf("rtp:") < 0)
                        {
                            Utils.GetQualifiedFilename(basePath, ref fileName);
                            newItem.Type = PlayListItem.PlayListItemType.AudioStream;
                        }
                        playlist.Add(newItem);
                        fileName     = "";
                        infoLine     = "";
                        durationLine = "";
                    }
                }
                line = file.ReadLine();
            }
            file.Close();

            if (fileName.Length > 0)
            {
                new PlayListItem(infoLine, fileName, 0);
            }


            return(true);
        }
Example #39
0
    /// <summary>
    /// Save player state (when form was resized)
    /// </summary>
    protected void SavePlayerState()
    {
      if (!_wasPlayingVideo && (g_Player.Playing && (g_Player.IsTV || g_Player.IsVideo || g_Player.IsDVD)))
      {
        _wasPlayingVideo = true;

        // Some Audio/video is playing
        _currentPlayerPos = g_Player.CurrentPosition;
        _currentPlayListType = PlaylistPlayer.CurrentPlaylistType;
        _currentPlayList = new PlayList();

        Log.Info("D3D: Saving fullscreen state for resume: {0}", Menu == null);
        var tempList = PlaylistPlayer.GetPlaylist(_currentPlayListType);
        if (tempList.Count == 0 && g_Player.IsDVD)
        {
          // DVD is playing
          var itemDVD = new PlayListItem {FileName = g_Player.CurrentFile, Played = true, Type = PlayListItem.PlayListItemType.DVD};
          tempList.Add(itemDVD);
        }

        foreach (var itemNew in tempList)
        {
          _currentPlayList.Add(itemNew);
        }

        _currentFile = PlaylistPlayer.Get(PlaylistPlayer.CurrentSong);
        if (_currentFile.Equals(string.Empty) && g_Player.IsDVD)
        {
          _currentFile = g_Player.CurrentFile;
        }

        Log.Info("D3D: Stopping media - Current playlist: Type: {0} / Size: {1} / Current item: {2} / Filename: {3} / Position: {4}",
                 _currentPlayListType, _currentPlayList.Count, PlaylistPlayer.CurrentSong, _currentFile, _currentPlayerPos);
        
        g_Player.Stop();

        _lastActiveWindow = GUIWindowManager.ActiveWindow;
      }
    }
Example #40
0
 protected override void AddItemToPlayList(GUIListItem listItem)
 {
   if (listItem.IsFolder)
   {
     // recursive
     if (listItem.Label == "..")
     {
       return;
     }
     
     List<GUIListItem> itemlist = _virtualDirectory.GetDirectoryUnProtectedExt(listItem.Path, true);
     
     foreach (GUIListItem item in itemlist)
     {
       AddItemToPlayList(item);
     }
   }
   else
   {
     if (Util.Utils.IsVideo(listItem.Path) && !PlayListFactory.IsPlayList(listItem.Path))
     {
       PlayListItem playlistItem = new PlayListItem();
       playlistItem.FileName = listItem.Path;
       playlistItem.Description = listItem.Label;
       playlistItem.Duration = listItem.Duration;
       playlistItem.Type = PlayListItem.PlayListItemType.Video;
       _playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO).Add(playlistItem);
     }
   }
 }
    public static void PlayMovie(int idMovie, bool requestPin)
    {
      int selectedFileIndex = 1;

      if (_isStacked)
      {
        selectedFileIndex = 0;
      }

      ArrayList movies = new ArrayList();
      VideoDatabase.GetFiles(idMovie, ref movies);
      if (movies.Count <= 0)
      {
        return;
      }
      
      if (!CheckMovie(idMovie))
      {
        return;
      }

      bool askForResumeMovie = true;
      int movieDuration = 0;

      //get all movies belonging to each other
      List<GUIListItem> items = new List<GUIListItem>();
      
      // Pin protection
      if (!requestPin)
      {
        items = _virtualDirectory.GetDirectoryUnProtectedExt(Path.GetDirectoryName((string)movies[0]), false);
      }
      else
      {
        items = _virtualDirectory.GetDirectoryExt(Path.GetDirectoryName((string)movies[0]));
      }

      if (items.Count <= 1)
      {
        return; // first item always ".." so 1 item means protected share
      }

      //check if we can resume 1 of those movies
      int timeMovieStopped = 0;
      bool asked = false;
      ArrayList newItems = new ArrayList();
      
      for (int i = 0; i < items.Count; ++i)
      {
        GUIListItem temporaryListItem = (GUIListItem)items[i];
        bool found = false;

        // reduce number of items to movie files only
        foreach (var movie in movies)
        {
          if (movie.ToString() == items[i].Path)
          {
            found = true;
            break;
          }
        }

        if (!found)
          continue;

        if ((Util.Utils.ShouldStack(temporaryListItem.Path, (string)movies[0])) && (movies.Count > 1))
        {
          if (!asked)
          {
            selectedFileIndex++;
          }
          IMDBMovie movieDetails = new IMDBMovie();
          int idFile = VideoDatabase.GetFileId(temporaryListItem.Path);
          if ((idMovie >= 0) && (idFile >= 0))
          {
            VideoDatabase.GetMovieInfo((string)movies[0], ref movieDetails);
            string title = Path.GetFileName((string)movies[0]);
            if ((VirtualDirectory.IsValidExtension((string)movies[0], Util.Utils.VideoExtensions, false)))
            {
              Util.Utils.RemoveStackEndings(ref title);
            }
            if (movieDetails.Title != string.Empty)
            {
              title = movieDetails.Title;
            }

            timeMovieStopped = VideoDatabase.GetMovieStopTime(idFile);
            if (timeMovieStopped > 0)
            {
              if (!asked)
              {
                asked = true;

                GUIResumeDialog.Result result =
                  GUIResumeDialog.ShowResumeDialog(title, movieDuration + timeMovieStopped,
                                                   GUIResumeDialog.MediaType.Video);

                if (result == GUIResumeDialog.Result.Abort)
                  return;

                if (result == GUIResumeDialog.Result.PlayFromBeginning)
                {
                  VideoDatabase.DeleteMovieStopTime(idFile);
                  newItems.Add(temporaryListItem);
                }
                else
                {
                  askForResumeMovie = false;
                  newItems.Add(temporaryListItem);
                }
              } //if (!asked)
              else
              {
                newItems.Add(temporaryListItem);
              }
            } //if (timeMovieStopped>0)
            else
            {
              newItems.Add(temporaryListItem);
            }

            // Total movie duration
            movieDuration += VideoDatabase.GetMovieDuration(idFile);
          }
          else //if (idMovie >=0)
          {
            newItems.Add(temporaryListItem);
          }
        } //if ( MediaPortal.Util.Utils.ShouldStack(temporaryListItem.Path, item.Path))
      }

      // If we have found stackable items, clear the movies array
      // so, that we can repopulate it.
      if (newItems.Count > 0)
      {
        movies.Clear();
      }

      for (int i = 0; i < newItems.Count; ++i)
      {
        GUIListItem temporaryListItem = (GUIListItem)newItems[i];
        if (Util.Utils.IsVideo(temporaryListItem.Path) && !PlayListFactory.IsPlayList(temporaryListItem.Path))
        {
          movies.Add(temporaryListItem.Path);
        }
      }

      if (movies.Count > 1)
      {
        if (askForResumeMovie)
        {
          GUIDialogFileStacking dlg =
            (GUIDialogFileStacking)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_FILESTACKING);
          if (null != dlg)
          {
            dlg.SetFiles(movies);
            dlg.DoModal(GUIWindowManager.ActiveWindow);
            selectedFileIndex = dlg.SelectedFile;
            if (selectedFileIndex < 1)
            {
              return;
            }
          }
        }
      }

      _playlistPlayer.Reset();
      _playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_VIDEO_TEMP;
      PlayList playlist = _playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO_TEMP);
      playlist.Clear();
      for (int i = selectedFileIndex - 1; i < movies.Count; ++i)
      {
        string movieFileName = (string)movies[i];
        PlayListItem newitem = new PlayListItem();
        newitem.FileName = movieFileName;
        newitem.Type = PlayListItem.PlayListItemType.Video;
        playlist.Add(newitem);
      }

      // play movie...
      PlayMovieFromPlayList(askForResumeMovie, requestPin);
    }
Example #42
0
    public static void PlayMovie(int idMovie, bool requestPin)
    {

      int selectedFileIndex = 1;

      if (IsStacked)
      {
        selectedFileIndex = 0;
      }

      ArrayList movieFiles = new ArrayList();
      VideoDatabase.GetFilesForMovie(idMovie, ref movieFiles);

      if (movieFiles.Count <= 0 || !CheckMovie(idMovie))
      {
        return;
      }

      bool askForResumeMovie = true;
      int movieDuration = 0;

      List<GUIListItem> items = new List<GUIListItem>();

      foreach (string file in movieFiles)
      {
        FileInformation fi = new FileInformation();
        GUIListItem item = new GUIListItem(Util.Utils.GetFilename(file), "", file, false, fi);
        items.Add(item);

        if (!WakeUpSrv(item.Path))
        {
          return;
        }
      }

      if (items.Count <= 0)
      {
        return;
      }

      if (requestPin)
      {
        string strDir = Path.GetDirectoryName(items[0].Path);

        if (strDir != null && strDir.EndsWith(@"\"))
        {
          strDir = strDir.Substring(0, strDir.Length - 1);
        }

        if (strDir == null || strDir.Length > 254)
        {
          Log.Warn("GUIVideoFiles.PlayTitleMovie: Received a path which contains too many chars");
          return;
        }

        string iPincodeCorrect;
        if (_virtualDirectory.IsProtectedShare(strDir, out iPincodeCorrect))
        {
          #region Pin protected

          bool retry = true;
          {
            while (retry)
            {
              //no, then ask user to enter the pincode
              GUIMessage msgGetPassword = new GUIMessage(GUIMessage.MessageType.GUI_MSG_GET_PASSWORD, 0, 0, 0, 0, 0, 0);
              GUIWindowManager.SendMessage(msgGetPassword);

              if (msgGetPassword.Label != iPincodeCorrect)
              {
                GUIMessage msgWrongPassword = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WRONG_PASSWORD, 0, 0, 0, 0, 0,
                                                             0);
                GUIWindowManager.SendMessage(msgWrongPassword);

                if (!(bool)msgWrongPassword.Object)
                {
                  return;
                }
              }
              else
              {
                retry = false;
              }
            }
          }

          #endregion
        }
      }

      //check if we can resume 1 of those movies
      if (items.Count > 1)
      {
        bool asked = false;

        for (int i = 0; i < items.Count; ++i)
        {
          GUIListItem temporaryListItem = (GUIListItem)items[i];

          if (!asked)
          {
            selectedFileIndex++;
          }

          IMDBMovie movieDetails = new IMDBMovie();
          int idFile = VideoDatabase.GetFileId(temporaryListItem.Path);

          if ((idMovie >= 0) && (idFile >= 0))
          {
            VideoDatabase.GetMovieInfo((string)movieFiles[0], ref movieDetails);
            string title = Path.GetFileName((string)movieFiles[0]);

            if ((VirtualDirectory.IsValidExtension((string)movieFiles[0], Util.Utils.VideoExtensions, false)))
            {
              Util.Utils.RemoveStackEndings(ref title);
            }

            if (movieDetails.Title != string.Empty)
            {
              title = movieDetails.Title;
            }

            int timeMovieStopped = VideoDatabase.GetMovieStopTime(idFile);

            if (timeMovieStopped > 0)
            {
              if (!asked)
              {
                asked = true;

                GUIResumeDialog.Result result =
                  GUIResumeDialog.ShowResumeDialog(title, movieDuration + timeMovieStopped,
                                                   GUIResumeDialog.MediaType.Video);

                if (result == GUIResumeDialog.Result.Abort)
                {
                  _playlistPlayer.Reset();
                  _playlistPlayer.CurrentPlaylistType = _currentPlaylistType;
                  _playlistPlayer.CurrentSong = _currentPlaylistIndex;
                  return;
                }

                if (result == GUIResumeDialog.Result.PlayFromBeginning)
                {
                  VideoDatabase.DeleteMovieStopTime(idFile);
                }
                else
                {
                  askForResumeMovie = false;
                }
              }
            }
            // Total movie duration
            movieDuration += VideoDatabase.GetVideoDuration(idFile);
          }
        }

        if (askForResumeMovie)
        {
          GUIDialogFileStacking dlg =
            (GUIDialogFileStacking)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_FILESTACKING);

          if (null != dlg)
          {
            dlg.SetFiles(movieFiles);
            dlg.DoModal(GUIWindowManager.ActiveWindow);
            selectedFileIndex = dlg.SelectedFile;
            if (selectedFileIndex < 1)
            {
              return;
            }
          }
        }
      }

      // Get current playlist
      _currentPlaylistType = new PlayListType();
      _currentPlaylistType = _playlistPlayer.CurrentPlaylistType;
      _currentPlaylistIndex = _playlistPlayer.CurrentSong;
      
      _playlistPlayer.Reset();
      _playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_VIDEO_TEMP;
      PlayList playlist = _playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO_TEMP);
      playlist.Clear();

      for (int i = selectedFileIndex - 1; i < movieFiles.Count; ++i)
      {
        string movieFileName = (string)movieFiles[i];
        PlayListItem newitem = new PlayListItem();
        newitem.FileName = movieFileName;
        newitem.Type = PlayListItem.PlayListItemType.Video;
        playlist.Add(newitem);
      }

      // play movie...
      PlayMovieFromPlayList(askForResumeMovie, requestPin);
    }
    protected override void OnClick(int iItem)
    {
      GUIListItem item = facadeLayout.SelectedListItem;
      _totalMovieDuration = 0;
      _isStacked = false;
      _stackedMovieFiles.Clear();

      if (item == null)
      {
        return;
      }
      bool isFolderAMovie = false;
      string path = item.Path;

      if (item.IsFolder && !item.IsRemote)
      {
        // Check if folder is actually a DVD. If so don't browse this folder, but play the DVD!
        if ((File.Exists(path + @"\VIDEO_TS\VIDEO_TS.IFO")) && (item.Label != ".."))
        {
          isFolderAMovie = true;
          path = item.Path + @"\VIDEO_TS\VIDEO_TS.IFO";
        }
        else
        {
          isFolderAMovie = false;
        }
      }

      if ((item.IsFolder && !isFolderAMovie))
        //-- Mars Warrior @ 03-sep-2004
      {
        _currentSelectedItem = -1;
        LoadDirectory(path);
      }
      else
      {
        if (!_virtualDirectory.RequestPin(path))
        {
          return;
        }
        if (_virtualDirectory.IsRemote(path))
        {
          if (!_virtualDirectory.IsRemoteFileDownloaded(path, item.FileInfo.Length))
          {
            if (!_virtualDirectory.ShouldWeDownloadFile(path))
            {
              return;
            }
            if (!_virtualDirectory.DownloadRemoteFile(path, item.FileInfo.Length))
            {
              //show message that we are unable to download the file
              GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SHOW_WARNING, 0, 0, 0, 0, 0, 0);
              msg.Param1 = 916;
              msg.Param2 = 920;
              msg.Param3 = 0;
              msg.Param4 = 0;
              GUIWindowManager.SendMessage(msg);

              return;
            }
            else
            {
              //download subtitle files
              Thread subLoaderThread = new Thread(new ThreadStart(this._downloadSubtitles));
              subLoaderThread.IsBackground = true;
              subLoaderThread.Name = "SubtitleLoader";
              subLoaderThread.Start();
            }
          }
        }

        if (item.FileInfo != null)
        {
          if (!_virtualDirectory.IsRemoteFileDownloaded(path, item.FileInfo.Length))
          {
            return;
          }
        }
        string movieFileName = path;
        movieFileName = _virtualDirectory.GetLocalFilename(movieFileName);

        // Set selected item
        _currentSelectedItem = facadeLayout.SelectedListItemIndex;
        if (PlayListFactory.IsPlayList(movieFileName))
        {
          LoadPlayList(movieFileName);
          return;
        }

        if (!CheckMovie(movieFileName))
        {
          return;
        }
        bool askForResumeMovie = true;
        if (_mapSettings.Stack)
        {
          int selectedFileIndex = 0;
          int movieDuration = 0;
          ArrayList movies = new ArrayList();

          #region Is all this really neccessary?!

          //get all movies belonging to each other
          List<GUIListItem> items = _virtualDirectory.GetDirectoryUnProtectedExt(_currentFolder, true);

          //check if we can resume 1 of those movies
          int timeMovieStopped = 0;
          bool asked = false;
          ArrayList newItems = new ArrayList();
          for (int i = 0; i < items.Count; ++i)
          {
            GUIListItem temporaryListItem = (GUIListItem)items[i];
            if (Util.Utils.ShouldStack(temporaryListItem.Path, path))
            {
              _isStacked = true;
              _stackedMovieFiles.Add(temporaryListItem.Path);
              if (!asked)
              {
                selectedFileIndex++;
              }
              IMDBMovie movieDetails = new IMDBMovie();
              int idFile = VideoDatabase.GetFileId(temporaryListItem.Path);
              int idMovie = VideoDatabase.GetMovieId(path);
              if ((idMovie >= 0) && (idFile >= 0))
              {
                VideoDatabase.GetMovieInfo(path, ref movieDetails);
                string title = Path.GetFileName(path);
                if ((VirtualDirectory.IsValidExtension(path, Util.Utils.VideoExtensions, false)))
                {
                  Util.Utils.RemoveStackEndings(ref title);
                }
                if (movieDetails.Title != string.Empty)
                {
                  title = movieDetails.Title;
                }

                timeMovieStopped = VideoDatabase.GetMovieStopTime(idFile);
                if (timeMovieStopped > 0)
                {
                  if (!asked)
                  {
                    asked = true;

                    GUIResumeDialog.Result result =
                      GUIResumeDialog.ShowResumeDialog(title, movieDuration + timeMovieStopped,
                                                       GUIResumeDialog.MediaType.Video);

                    if (result == GUIResumeDialog.Result.Abort)
                      return;

                    if (result == GUIResumeDialog.Result.PlayFromBeginning)
                    {
                      VideoDatabase.DeleteMovieStopTime(idFile);
                      newItems.Add(temporaryListItem);
                    }
                    else
                    {
                      askForResumeMovie = false;
                      newItems.Add(temporaryListItem);
                    }
                  } //if (!asked)
                  else
                  {
                    newItems.Add(temporaryListItem);
                  }
                } //if (timeMovieStopped>0)
                else
                {
                  newItems.Add(temporaryListItem);
                }

                // Total movie duration
                movieDuration += VideoDatabase.GetMovieDuration(idFile);
                _totalMovieDuration = movieDuration;
              }
              else //if (idMovie >=0)
              {
                newItems.Add(temporaryListItem);
              }
            } //if ( MediaPortal.Util.Utils.ShouldStack(temporaryListItem.Path, path))
          }

          for (int i = 0; i < newItems.Count; ++i)
          {
            GUIListItem temporaryListItem = (GUIListItem)newItems[i];
            if (Util.Utils.IsVideo(temporaryListItem.Path) && !PlayListFactory.IsPlayList(temporaryListItem.Path))
            {
              if (Util.Utils.ShouldStack(temporaryListItem.Path, path))
              {
                movies.Add(temporaryListItem.Path);
              }
            }
          }
          if (movies.Count == 0)
          {
            movies.Add(movieFileName);
          }

          #endregion

          if (movies.Count <= 0)
          {
            return;
          }
          if (movies.Count > 1)
          {
            //TODO
            movies.Sort();

            for (int i = 0; i < movies.Count; ++i)
            {
              AddFileToDatabase((string)movies[i]);
            }
            // Stacked movies duration
            if (_totalMovieDuration == 0)
            {
              MovieDuration(movies);
              _stackedMovieFiles = movies;
            }

            if (askForResumeMovie)
            {
              GUIDialogFileStacking dlg =
                (GUIDialogFileStacking)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_FILESTACKING);
              if (null != dlg)
              {
                dlg.SetFiles(movies);
                dlg.DoModal(GetID);
                selectedFileIndex = dlg.SelectedFile;
                if (selectedFileIndex < 1)
                {
                  return;
                }
              }
            }
          }
          else if (movies.Count == 1)
          {
            AddFileToDatabase((string)movies[0]);
            MovieDuration(movies);
          }
          _playlistPlayer.Reset();
          _playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_VIDEO_TEMP;
          PlayList playlist = _playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO_TEMP);
          playlist.Clear();
          for (int i = 0; i < (int)movies.Count; ++i)
          {
            movieFileName = (string)movies[i];
            PlayListItem itemNew = new PlayListItem();
            itemNew.FileName = movieFileName;
            itemNew.Type = PlayListItem.PlayListItemType.Video;
            playlist.Add(itemNew);
          }

          // play movie...
          PlayMovieFromPlayList(askForResumeMovie, selectedFileIndex - 1, true);
          return;
        }

        // play movie...
        AddFileToDatabase(movieFileName);

        _playlistPlayer.Reset();
        _playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_VIDEO_TEMP;
        PlayList newPlayList = _playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO_TEMP);
        newPlayList.Clear();
        PlayListItem NewItem = new PlayListItem();
        NewItem.FileName = movieFileName;
        NewItem.Type = PlayListItem.PlayListItemType.Video;
        newPlayList.Add(NewItem);
        PlayMovieFromPlayList(true, true);
        /*
                //TODO
                if (g_Player.Play(movieFileName))
                {
                  if ( MediaPortal.Util.Utils.IsVideo(movieFileName))
                  {
                    GUIGraphicsContext.IsFullScreenVideo = true;
                    GUIWindowManager.ActivateWindow((int)GUIWindow.Window.WINDOW_FULLSCREEN_VIDEO);
                  }
                }*/
      }
    }
Example #44
0
    protected override void OnClick(int iItem)
    {
      GUIListItem item = facadeLayout.SelectedListItem;
      TotalMovieDuration = 0;
      IsStacked = false;
      StackedMovieFiles.Clear();

      if (item == null)
      {
        _playClicked = false;
        return;
      }
      
      if (!WakeUpSrv(item.Path))
      {
        return;
      }

      string path = item.Path;

      if (item.IsBdDvdFolder)
      {
        // Check if folder is actually a DVD. If so don't browse this folder, but play the DVD!
        if (File.Exists(path + @"\VIDEO_TS\VIDEO_TS.IFO"))
        {
          path = item.Path + @"\VIDEO_TS\VIDEO_TS.IFO";
        }
        // Then it's a Blu-Ray. Play the Blu-Ray!
        else
        {
          path = item.Path + @"\BDMV\index.bdmv";
        }
      }

      if ((item.IsFolder && !item.IsBdDvdFolder))
      {
        // Play all in folder
        if (_playClicked)
        {
          if (!item.IsRemote && item.Label != ".." && !VirtualDirectory.IsImageFile(Path.GetExtension(item.Path)))
          {
            if (!_virtualDirectory.RequestPin(item.Path))
            {
              _playClicked = false;
              return;
            }

            OnPlayAll(item.Path);
            _playClicked = false;
          }
        }
        else
        {
          _currentSelectedItem = -1;

          if (facadeLayout != null)
          {
            _history.Set(facadeLayout.SelectedListItemIndex.ToString(), _currentFolder);
          }

          LoadDirectory(path, true);
        }
      }
      else
      {
        if (!_virtualDirectory.RequestPin(path))
        {
          _playClicked = false;
          return;
        }
        
        if (_virtualDirectory.IsRemote(path))
        {
          if (!_virtualDirectory.IsRemoteFileDownloaded(path, item.FileInfo.Length))
          {
            if (!_virtualDirectory.ShouldWeDownloadFile(path))
            {
              _playClicked = false;
              return;
            }
            
            if (!_virtualDirectory.DownloadRemoteFile(path, item.FileInfo.Length))
            {
              //show message that we are unable to download the file
              GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_SHOW_WARNING, 0, 0, 0, 0, 0, 0);
              msg.Param1 = 916;
              msg.Param2 = 920;
              msg.Param3 = 0;
              msg.Param4 = 0;
              GUIWindowManager.SendMessage(msg);
              _playClicked = false;
              return;
            }
            //download subtitle files
            Thread subLoaderThread = new Thread(DownloadSubtitles);
            subLoaderThread.IsBackground = true;
            subLoaderThread.Name = "SubtitleLoader";
            subLoaderThread.Start();
          }
        }

        if (item.FileInfo != null)
        {
          if (!_virtualDirectory.IsRemoteFileDownloaded(path, item.FileInfo.Length))
          {
            _playClicked = false;
            return;
          }
        }
        
        string movieFileName = path;
        movieFileName = _virtualDirectory.GetLocalFilename(movieFileName);

        if (PlayListFactory.IsPlayList(movieFileName))
        {
          LoadPlayList(movieFileName);
          _playClicked = false;
          return;
        }

        if (!CheckMovie(movieFileName))
        {
          _playClicked = false;
          return;
        }

        if (_videoInfoInShare && VideoDatabase.HasMovieInfo(movieFileName) && !_playClicked)
        {
          OnInfo(facadeLayout.SelectedListItemIndex);
          return;
        }

        bool askForResumeMovie = true;
        _playClicked = false;

        #region StackEnabled and file is stackable

        // Proceed to file stack check if file is stackable
        if (_mapSettings.Stack && IsFileStackable(movieFileName))
        {
          IsStacked = true;
          int selectedFileIndex = 0;
          int movieDuration = 0;
          ArrayList movies = new ArrayList();
          List<GUIListItem> items = new List<GUIListItem>();
          IMDBMovie movie = item.AlbumInfoTag as IMDBMovie;
          
          // This will return all stackable files for current clicked item
          // Also will add all stackable files to videodatabase if they are not exist
          StackedMovieFiles = AddFileToDatabase(movieFileName);
          
          // Add movie files to list
          foreach (string file in StackedMovieFiles)
          {
            FileInformation fi = new FileInformation();
            GUIListItem itemMovie = new GUIListItem(Util.Utils.GetFilename(file), "", file, false, fi);
            items.Add(itemMovie);
          }
          
          // In the list must be at least 2 files so we check stackable movie for resume 
          // (which file have a stop time)
          bool asked = false;
          string title = item.Label; // Dlg title

          if (movie != null && !movie.IsEmpty)
          {
            title = movie.Title;
          }
          
          for (int i = 0; i < items.Count; ++i)
          {
            IMDBMovie.SetMovieData(items[i]); // This will set IMDBMovie object and it will never be null
            movie = items[i].AlbumInfoTag as IMDBMovie;
             
            if (!asked)
            {
              selectedFileIndex++;
            }

            int idFile = VideoDatabase.GetFileId(movie.VideoFileName);

            if (idFile != -1)
            {
              int timeMovieStopped = VideoDatabase.GetMovieStopTime(idFile);
                
              if (timeMovieStopped > 0)
              {
                if (!asked)
                {
                  asked = true;
                  GUIResumeDialog.Result result =
                    GUIResumeDialog.ShowResumeDialog(title, movieDuration + timeMovieStopped,
                                                      GUIResumeDialog.MediaType.Video);

                  if (result == GUIResumeDialog.Result.Abort)
                  {
                    _playlistPlayer.Reset();
                    _playlistPlayer.CurrentPlaylistType = _currentPlaylistType;
                    _playlistPlayer.CurrentSong = _currentPlaylistIndex;
                    return;
                  }

                  if (result == GUIResumeDialog.Result.PlayFromBeginning)
                  {
                    VideoDatabase.DeleteMovieStopTime(idFile);
                  }
                  else
                  {
                    askForResumeMovie = false;
                  }
                }
              }
              
              // Total movie duration
              movieDuration += VideoDatabase.GetVideoDuration(idFile);
              TotalMovieDuration = movieDuration;
            }
          }

          for (int i = 0; i < items.Count; ++i)
          {
            GUIListItem temporaryListItem = (GUIListItem)items[i];
            movie = (IMDBMovie)temporaryListItem.AlbumInfoTag;

            if (Util.Utils.IsVideo(movie.VideoFileName) && !PlayListFactory.IsPlayList(movie.VideoFileName))
            {
              movies.Add(movie.VideoFileName);
            }
          }
          
          if (movies.Count == 0)
          {
            movies.Add(movieFileName);
          }

          if (movies.Count > 1)
          {
            movies.Sort();

            // Stacked movies duration
            if (TotalMovieDuration == 0)
            {
              MovieDuration(movies, false);
              StackedMovieFiles = movies;
            }

            // Ask for resume
            if (askForResumeMovie)
            {
              GUIDialogFileStacking dlg =
                (GUIDialogFileStacking) GUIWindowManager.GetWindow((int) Window.WINDOW_DIALOG_FILESTACKING);
              
              if (null != dlg)
              {
                dlg.SetFiles(movies);
                dlg.DoModal(GetID);
                selectedFileIndex = dlg.SelectedFile;
                
                if (selectedFileIndex < 1)
                {
                  return;
                }
              }
            }
          }
          // This can happen if user have one file and it is stackable (filename ends with CDx...)
          else
          {
            MovieDuration(movies, false);
          }

          // Get current playlist
          _currentPlaylistType = new PlayListType();
          _currentPlaylistType = _playlistPlayer.CurrentPlaylistType;
          _currentPlaylistIndex = _playlistPlayer.CurrentSong;
          
          _playlistPlayer.Reset();
          _playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_VIDEO_TEMP;
          PlayList playlist = _playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO_TEMP);
          playlist.Clear();
          
          for (int i = 0; i < (int) movies.Count; ++i)
          {
            movieFileName = (string) movies[i];
            PlayListItem itemNew = new PlayListItem();
            itemNew.FileName = movieFileName;
            itemNew.Type = PlayListItem.PlayListItemType.Video;
            playlist.Add(itemNew);
          }

          // play movie...(2 or more files)
          PlayMovieFromPlayList(askForResumeMovie, selectedFileIndex - 1, true);
          return;
        }

        #endregion

        #region StackDisabled or file not stackable

        // play movie...(only 1 file)
        AddFileToDatabase(movieFileName);

        // Get current playlist
        _currentPlaylistType = new PlayListType();
        _currentPlaylistType = _playlistPlayer.CurrentPlaylistType;
        _currentPlaylistIndex = _playlistPlayer.CurrentSong;

        _playlistPlayer.Reset();
        _playlistPlayer.CurrentPlaylistType = PlayListType.PLAYLIST_VIDEO_TEMP;
        PlayList newPlayList = _playlistPlayer.GetPlaylist(PlayListType.PLAYLIST_VIDEO_TEMP);
        newPlayList.Clear();
        PlayListItem NewItem = new PlayListItem();
        NewItem.FileName = movieFileName;
        NewItem.Type = PlayListItem.PlayListItemType.Video;
        newPlayList.Add(NewItem);
        PlayMovieFromPlayList(true, true);

        #endregion
      }
    }
        public void OnMessage(GUIMessage message)
        {
            switch (message.Message)
            {
            case GUIMessage.MessageType.GUI_MSG_PLAYBACK_STOPPED:
            {
                PlayListItem item = GetCurrentItem();
                if (item != null)
                {
                    if (item.Type != PlayListItem.PlayListItemType.AudioStream)
                    {
                        Reset();
                        _currentPlayList = PlayListType.PLAYLIST_NONE;
                    }
                }
                GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_ITEM_FOCUS, 0, 0, 0, -1, 0, null);
                GUIGraphicsContext.SendMessage(msg);
            }
            break;

            // SV Allows BassMusicPlayer to continuously play
            case GUIMessage.MessageType.GUI_MSG_PLAYBACK_CROSSFADING:
            {
                // This message is only sent by BASS in gapless/crossfading mode
                PlayNext();
            }
            break;

            case GUIMessage.MessageType.GUI_MSG_PLAYBACK_ENDED:
            {
                // This message is sent by both the internal and BASS player
                // In case of gapless/crossfading it is only sent after the last song
                PlayNext(false);
                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:
            {
                Log.Info("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:
            {
                Log.Info("Playlistplayer: Stop file");
                g_Player.Stop();
            }
            break;

            case GUIMessage.MessageType.GUI_MSG_SEEK_FILE_PERCENTAGE:
            {
                Log.Info("Playlistplayer: SeekPercent ({0}%)", message.Param1);
                g_Player.SeekAsolutePercentage(message.Param1);
                Log.Debug("Playlistplayer: SeekPercent ({0}%) done", message.Param1);
            }
            break;

            case GUIMessage.MessageType.GUI_MSG_SEEK_FILE_END:
            {
                double duration = g_Player.Duration;
                double position = g_Player.CurrentPosition;
                if (position < duration - 1d)
                {
                    Log.Info("Playlistplayer: SeekEnd ({0})", duration);
                    g_Player.SeekAbsolute(duration - 2d);
                    Log.Debug("Playlistplayer: SeekEnd ({0}) done", g_Player.CurrentPosition);
                }
            }
            break;

            case GUIMessage.MessageType.GUI_MSG_SEEK_POSITION:
            {
                g_Player.SeekAbsolute(message.Param1);
            }
            break;
            }
        }
Example #46
0
        public bool Load(PlayList playlist, string fileName, string label)
        {
            string basePath = String.Empty;
            Stream stream;

            if (fileName.ToLower().StartsWith("http"))
            {
                // We've got a URL pointing to a pls
                WebClient client = new WebClient();
                client.Proxy.Credentials = CredentialCache.DefaultCredentials;
                byte[] buffer = client.DownloadData(fileName);
                stream = new MemoryStream(buffer);
            }
            else
            {
                // We've got a plain pls file
                basePath = Path.GetDirectoryName(Path.GetFullPath(fileName));
                stream   = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            }

            playlist.Clear();
            playlist.Name = Path.GetFileName(fileName);
            Encoding     fileEncoding = Encoding.Default;
            StreamReader file         = new StreamReader(stream, fileEncoding, true);

            try
            {
                if (file == null)
                {
                    return(false);
                }

                string line;
                line = file.ReadLine();
                if (line == null)
                {
                    file.Close();
                    return(false);
                }

                string strLine = line.Trim();


                //CUtil::RemoveCRLF(strLine);
                if (strLine != START_PLAYLIST_MARKER)
                {
                    if (strLine.StartsWith("http") || strLine.StartsWith("HTTP") ||
                        strLine.StartsWith("mms") || strLine.StartsWith("MMS") ||
                        strLine.StartsWith("rtp") || strLine.StartsWith("RTP"))
                    {
                        PlayListItem newItem = new PlayListItem(strLine, strLine, 0);
                        newItem.Type = PlayListItem.PlayListItemType.AudioStream;
                        playlist.Add(newItem);
                        file.Close();
                        return(true);
                    }
                    fileEncoding = Encoding.Default;
                    stream       = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                    file         = new StreamReader(stream, fileEncoding, true);

                    //file.Close();
                    //return false;
                }

                string infoLine     = "";
                string durationLine = "";
                fileName = "";
                line     = file.ReadLine();
                while (line != null)
                {
                    strLine = line.Trim();
                    //CUtil::RemoveCRLF(strLine);
                    int equalPos = strLine.IndexOf("=");
                    if (equalPos > 0)
                    {
                        string leftPart = strLine.Substring(0, equalPos);
                        equalPos++;
                        string valuePart = strLine.Substring(equalPos);
                        leftPart = leftPart.ToLower();
                        if (leftPart.StartsWith("file"))
                        {
                            if (valuePart.Length > 0 && valuePart[0] == '#')
                            {
                                line = file.ReadLine();
                                continue;
                            }

                            if (fileName.Length != 0)
                            {
                                PlayListItem newItem = new PlayListItem(infoLine, fileName, 0);
                                playlist.Add(newItem);
                                fileName     = "";
                                infoLine     = "";
                                durationLine = "";
                            }
                            fileName = valuePart;
                        }
                        if (leftPart.StartsWith("title"))
                        {
                            infoLine = valuePart;
                        }
                        else
                        {
                            if (infoLine == "")
                            {
                                // For a URL we need to set the label in for the Playlist name, in order to be played.
                                if (label != null && fileName.ToLower().StartsWith("http"))
                                {
                                    infoLine = label;
                                }
                                else
                                {
                                    infoLine = Path.GetFileName(fileName);
                                }
                            }
                        }
                        if (leftPart.StartsWith("length"))
                        {
                            durationLine = valuePart;
                        }
                        if (leftPart == "playlistname")
                        {
                            playlist.Name = valuePart;
                        }

                        if (durationLine.Length > 0 && infoLine.Length > 0 && fileName.Length > 0)
                        {
                            int duration = Int32.Parse(durationLine);

                            // Remove trailing slashes. Might cause playback issues
                            if (fileName.EndsWith("/"))
                            {
                                fileName = fileName.Substring(0, fileName.Length - 1);
                            }

                            PlayListItem newItem = new PlayListItem(infoLine, fileName, duration);
                            if (fileName.ToLower().StartsWith("http:") || fileName.ToLower().StartsWith("https:") ||
                                fileName.ToLower().StartsWith("mms:") || fileName.ToLower().StartsWith("rtp:"))
                            {
                                newItem.Type = PlayListItem.PlayListItemType.AudioStream;
                            }
                            else
                            {
                                Util.Utils.GetQualifiedFilename(basePath, ref fileName);
                                newItem.FileName = fileName;
                                newItem.Type     = PlayListItem.PlayListItemType.Audio;
                            }
                            playlist.Add(newItem);
                            fileName     = "";
                            infoLine     = "";
                            durationLine = "";
                        }
                    }
                    line = file.ReadLine();
                }
                file.Close();

                if (fileName.Length > 0)
                {
                    PlayListItem newItem = new PlayListItem(infoLine, fileName, 0);
                }
            }
            finally
            {
                if (file != null)
                {
                    file.Close();
                }
            }

            return(true);
        }
        public bool Play(int iSong, bool setFullScreenVideo)
        {
            // if play returns false PlayNext is called but this does not help against selecting an invalid track
            bool skipmissing = false;

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

                //int previousItem = _currentItem;
                _currentItem = iSong;
                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();
                }

                //Log.Debug("PlaylistPlayer: Play - {0}", item.FileName);
                bool playResult = false;
                if (_currentPlayList == PlayListType.PLAYLIST_MUSIC_VIDEO)
                {
                    playResult = g_Player.PlayVideoStream(item.FileName, item.Description);
                }
                else if (item.Type == PlayListItem.PlayListItemType.AudioStream) // Internet Radio
                {
                    playResult = g_Player.PlayAudioStream(item.FileName);
                }
                else
                {
                    playResult = g_Player.Play(item.FileName);
                }
                if (!playResult)
                {
                    //	Count entries in current playlist
                    //	that couldn't be played
                    _entriesNotFound++;
                    Log.Error("PlaylistPlayer: *** unable to play - {0} - skipping track!", item.FileName);

                    // do not try to play the next movie or internetstream in the list
                    if (Util.Utils.IsVideo(item.FileName) || Util.Utils.IsLastFMStream(item.FileName))
                    {
                        skipmissing = false;
                    }
                    else
                    {
                        skipmissing = true;
                    }

                    iSong++;
                }
                else
                {
                    item.Played = true;
                    skipmissing = false;
                    if (Util.Utils.IsVideo(item.FileName) && setFullScreenVideo)
                    {
                        if (g_Player.HasVideo)
                        {
                            g_Player.ShowFullScreenWindow();
                        }
                    }
                }
            } while (skipmissing);
            return(g_Player.Playing);
        }
    /// <summary>
    /// Add or enque a song to the current playlist - call OnSongInserted() after this!!!
    /// </summary>
    /// <param name="song">the song to add</param>
    /// <returns>if the action was successful</returns>
    private bool AddSongToPlaylist(ref Song song)
    {
      PlayList playlist;
      if (PlaylistPlayer.CurrentPlaylistType == PlayListType.PLAYLIST_MUSIC_TEMP)
      {
        playlist = PlaylistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC_TEMP);
      }
      else
      {
        playlist = PlaylistPlayer.GetPlaylist(PlayListType.PLAYLIST_MUSIC);
      }
      
      if (playlist == null)
      {
        return false;
      }

      //add to playlist
      PlayListItem playlistItem = new PlayListItem();
      playlistItem.Type = PlayListItem.PlayListItemType.Audio;
      StringBuilder sb = new StringBuilder();

      playlistItem.FileName = song.FileName;
      sb.Append(song.Track);
      sb.Append(". ");
      sb.Append(song.Artist);
      sb.Append(" - ");
      sb.Append(song.Title);
      playlistItem.Description = sb.ToString();
      playlistItem.Duration = song.Duration;

      playlistItem.MusicTag = song.ToMusicTag();
      playlist.Add(playlistItem);

      OnSongInserted();
      return true;
    }
Example #49
0
    public PlayListItem ToPlayListItem()
    {
      PlayListItem pli = new PlayListItem();

      pli.Type = PlayListItem.PlayListItemType.Audio;
      pli.FileName = this.FileName;
      pli.Description = this.Title;
      pli.Duration = this.Duration;
      MusicTag tag = this.ToMusicTag();
      pli.MusicTag = tag;

      return pli;
    }