示例#1
0
        public void Save(PlayList playListParam, string fileName)
        {
            try
            {
                using (StreamWriter writer = new StreamWriter(fileName, false, Encoding.UTF8))
                {
                    writer.WriteLine(M3U_START_MARKER);

                    foreach (PlayListItem item in playListParam)
                    {
                        writer.WriteLine("{0}:{1},{2}", M3U_INFO_MARKER, item.Duration, item.Description);
                        writer.WriteLine("{0}", item.FileName);
                    }
                }
            }
            catch (Exception) {}
        }
        public void ReplacePlaylist(PlayListType nPlayList, PlayList playlist)
        {
            if (playlist == null)
            {
                playlist = new PlayList();
            }

            playlist.OnChanged -= NotifyChange;
            playlist.OnChanged += new PlayList.OnChangedDelegate(NotifyChange);

            switch (nPlayList)
            {
            case PlayListType.PLAYLIST_MUSIC:
                _musicPlayList = playlist;
                break;

            case PlayListType.PLAYLIST_MUSIC_TEMP:
                _tempMusicPlayList = playlist;
                break;

            case PlayListType.PLAYLIST_VIDEO:
                _videoPlayList = playlist;
                break;

            case PlayListType.PLAYLIST_VIDEO_TEMP:
                _tempVideoPlayList = playlist;
                break;

            case PlayListType.PLAYLIST_MUSIC_VIDEO:
                _musicVideoPlayList = playlist;
                break;

            case PlayListType.PLAYLIST_RADIO_STREAMS:
                _radioStreamPlayList = playlist;
                break;

            default:
                _emptyPlayList = playlist;
                break;
            }

            NotifyChange(playlist);
        }
        public void Play(string filename)
        {
            if (_currentPlayList == PlayListType.PLAYLIST_NONE)
            {
                return;
            }

            PlayList playlist = GetPlaylist(_currentPlayList);

            for (int i = 0; i < playlist.Count; ++i)
            {
                PlayListItem item = playlist[i];
                if (item.FileName.Equals(filename))
                {
                    Play(i);
                    return;
                }
            }
        }
        private void NotifyChange(PlayList playlist)
        {
            PlayListType nPlaylist = PlayListType.PLAYLIST_NONE;

            if (_musicPlayList == playlist)
            {
                nPlaylist = PlayListType.PLAYLIST_MUSIC;
            }
            else if (_tempMusicPlayList == playlist)
            {
                nPlaylist = PlayListType.PLAYLIST_MUSIC_TEMP;
            }
            else if (_videoPlayList == playlist)
            {
                nPlaylist = PlayListType.PLAYLIST_VIDEO;
            }
            else if (_tempVideoPlayList == playlist)
            {
                nPlaylist = PlayListType.PLAYLIST_VIDEO_TEMP;
            }
            else if (_musicVideoPlayList == playlist)
            {
                nPlaylist = PlayListType.PLAYLIST_MUSIC_VIDEO;
            }
            else if (_radioStreamPlayList == playlist)
            {
                nPlaylist = PlayListType.PLAYLIST_RADIO_STREAMS;
            }
            else if (_lastFMPlaylist == playlist)
            {
                nPlaylist = PlayListType.PLAYLIST_LAST_FM;
            }
            else
            {
                nPlaylist = PlayListType.PLAYLIST_NONE;
            }

            if (nPlaylist != PlayListType.PLAYLIST_NONE && PlaylistChanged != null)
            {
                PlaylistChanged(nPlaylist, playlist);
            }
        }
示例#5
0
        public void Save(PlayList playlist, string fileName)
        {
            try
            {
                using (StreamWriter writer = new StreamWriter(fileName, false, Encoding.UTF8))
                {
                    writer.WriteLine(M3U_START_MARKER);

                    foreach (PlayListItem item in playlist)
                    {
                        writer.WriteLine("{0}:{1},{2}", M3U_INFO_MARKER, item.Duration, item.Description);
                        writer.WriteLine("{0}", item.FileName);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Info("failed to save a playlist {0}. err: {1} stack: {2}", fileName, e.Message, e.StackTrace);
            }
        }
        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);
        }
示例#7
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);
            }
        }
示例#8
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);
            }
        }
示例#9
0
        public bool Load(PlayList incomingPlaylist, string playlistFileName)
        {
            if (playlistFileName == null)
            {
                return(false);
            }
            playlist = incomingPlaylist;
            playlist.Clear();

            try
            {
                playlist.Name = Path.GetFileName(playlistFileName);
                basePath      = Path.GetDirectoryName(Path.GetFullPath(playlistFileName));

                using (file = new StreamReader(playlistFileName, Encoding.Default, true))
                {
                    if (file == null)
                    {
                        return(false);
                    }

                    string line = file.ReadLine();
                    if (line == null || line.Length == 0)
                    {
                        return(false);
                    }

                    string trimmedLine = line.Trim();

                    if (trimmedLine != M3U_START_MARKER)
                    {
                        string fileName = trimmedLine;
                        if (!AddItem("", 0, fileName))
                        {
                            return(false);
                        }
                    }

                    line = file.ReadLine();
                    while (line != null)
                    {
                        trimmedLine = line.Trim();

                        if (trimmedLine != "")
                        {
                            if (trimmedLine.StartsWith(M3U_INFO_MARKER))
                            {
                                string songName  = null;
                                int    lDuration = 0;

                                if (ExtractM3uInfo(trimmedLine, ref songName, ref lDuration))
                                {
                                    line = file.ReadLine();
                                    if (!AddItem(songName, lDuration, line))
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                if (!AddItem("", 0, trimmedLine))
                                {
                                    break;
                                }
                            }
                        }
                        line = file.ReadLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Info("exception loading playlist {0} err:{1} stack:{2}", playlistFileName, ex.Message, ex.StackTrace);
                return(false);
            }
            return(true);
        }
示例#10
0
 public bool Load(PlayList playlist, string fileName, string label)
 {
     return(Load(playlist, fileName));
 }
示例#11
0
        public bool Load(PlayList incomingPlaylist, string playlistFileName)
        {
            if (playlistFileName == null)
            {
                return(false);
            }
            playlist = incomingPlaylist;
            playlist.Clear();

            try
            {
                playlist.Name = Path.GetFileName(playlistFileName);
                basePath      = Path.GetDirectoryName(Path.GetFullPath(playlistFileName));

                using (file = new StreamReader(playlistFileName))
                {
                    if (file == null)
                    {
                        return(false);
                    }

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

                    string trimmedLine = line.Trim();

                    if (trimmedLine != M3U_START_MARKER)
                    {
                        string fileName = trimmedLine;
                        if (!AddItem("", 0, fileName))
                        {
                            return(false);
                        }
                    }

                    line = file.ReadLine();
                    while (line != null)
                    {
                        trimmedLine = line.Trim();

                        if (trimmedLine != "")
                        {
                            if (trimmedLine.StartsWith(M3U_INFO_MARKER))
                            {
                                string songName  = null;
                                int    lDuration = 0;

                                if (ExtractM3uInfo(trimmedLine, ref songName, ref lDuration))
                                {
                                    line = file.ReadLine();
                                    if (!AddItem(songName, lDuration, line))
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                if (!AddItem("", 0, trimmedLine))
                                {
                                    break;
                                }
                            }
                        }
                        line = file.ReadLine();
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }
            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);
        }
示例#13
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);
        }
示例#14
0
 public bool Load(PlayList playlist, string fileName)
 {
     return(Load(playlist, fileName, null));
 }
示例#15
0
 public void Save(PlayList playlist, string fileName)
 {
     throw new Exception("The method or operation is not implemented.");
 }
示例#16
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);
        }