Logo Search packages:      
Sourcecode: jlgui version File versions  Download package

boolean javazoom::jlgui::player::amp::playlist::BasePlaylist::loadPLS ( String  filename  )  [inline, protected]

Load playlist in PLS format.

Parameters:
filename 
Returns:

Definition at line 211 of file BasePlaylist.java.

References appendItem(), and javazoom::jlgui::player::amp::util::Config::getLastDir().

Referenced by load().

    {
        Config config = Config.getInstance();
        _playlist = new Vector();
        boolean loaded = false;
        BufferedReader br = null;
        try
        {
            // Playlist from URL ? (http:, ftp:, file: ....)
            if (Config.startWithProtocol(filename))
            {
                br = new BufferedReader(new InputStreamReader((new URL(filename)).openStream()));
            }
            else
            {
                br = new BufferedReader(new FileReader(filename));
            }
            String line = null;
            String songName = null;
            String songFile = null;
            String songLength = null;
            while ((line = br.readLine()) != null)
            {
                if (line.trim().length() == 0) continue;
                if ((line.toLowerCase().startsWith("file")))
                {
                    StringTokenizer st = new StringTokenizer(line, "=");
                    st.nextToken();
                    songFile = st.nextToken().trim();
                }
                else if ((line.toLowerCase().startsWith("title")))
                {
                    StringTokenizer st = new StringTokenizer(line, "=");
                    st.nextToken();
                    songName = st.nextToken().trim();
                }
                else if ((line.toLowerCase().startsWith("length")))
                {
                    StringTokenizer st = new StringTokenizer(line, "=");
                    st.nextToken();
                    songLength = st.nextToken().trim();
                }
                // New entry ?
                if (songFile != null)
                {
                    PlaylistItem pli = null;
                    if (songName == null) songName = songFile;
                    if (songLength == null) songLength = "-1";
                    if (Config.startWithProtocol(songFile))
                    {
                        // URL.
                        pli = new PlaylistItem(songName, songFile, Long.parseLong(songLength), false);
                    }
                    else
                    {
                        // File.
                        File f = new File(songFile);
                        if (f.exists())
                        {
                            pli = new PlaylistItem(songName, songFile, Long.parseLong(songLength), true);
                        }
                        else
                        {
                            // Try relative path.
                            f = new File(config.getLastDir() + songFile);
                            if (f.exists())
                            {
                                pli = new PlaylistItem(songName, config.getLastDir() + songFile, Long.parseLong(songLength), true);
                            }
                            else
                            {
                                // Try optional PLS home.
                                if (PLSHome != null)
                                {
                                    if (Config.startWithProtocol(PLSHome))
                                    {
                                        pli = new PlaylistItem(songName, PLSHome + songFile, Long.parseLong(songLength), false);
                                    }
                                    else
                                    {
                                        pli = new PlaylistItem(songName, PLSHome + songFile, Long.parseLong(songLength), true);
                                    }
                                }
                            }
                        }
                    }
                    if (pli != null) this.appendItem(pli);
                    songName = null;
                    songFile = null;
                    songLength = null;
                }
            }
            loaded = true;
        }
        catch (Exception e)
        {
            log.debug("Can't load .pls playlist", e);
        }
        finally
        {
            try
            {
                if (br != null)
                {
                    br.close();
                }
            }
            catch (Exception ioe)
            {
                log.info("Can't close .pls playlist", ioe);
            }
        }
        return loaded;
    }


Generated by  Doxygen 1.6.0   Back to index