예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
        }
예제 #4
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);
            }
        }
예제 #5
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);
            }
        }
예제 #6
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);
        }
예제 #7
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);
        }