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

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

Load playlist from M3U format.

Parameters:
filename 
Returns:

Definition at line 92 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.startsWith("#"))
                {
                    if (line.toUpperCase().startsWith("#EXTINF"))
                    {
                        int indA = line.indexOf(",", 0);
                        if (indA != -1)
                        {
                            songName = line.substring(indA + 1, line.length());
                        }
                        int indB = line.indexOf(":", 0);
                        if (indB != -1)
                        {
                            if (indB < indA) songLength = (line.substring(indB + 1, indA)).trim();
                        }
                    }
                }
                else
                {
                    songFile = line;
                    if (songName == null) songName = songFile;
                    if (songLength == null) songLength = "-1";
                    PlaylistItem pli = null;
                    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 M3U home.
                                if (M3UHome != null)
                                {
                                    if (Config.startWithProtocol(M3UHome))
                                    {
                                        pli = new PlaylistItem(songName, M3UHome + songFile, Long.parseLong(songLength), false);
                                    }
                                    else
                                    {
                                        pli = new PlaylistItem(songName, M3UHome + songFile, Long.parseLong(songLength), true);
                                    }
                                }
                            }
                        }
                    }
                    if (pli != null) this.appendItem(pli);
                    songFile = null;
                    songName = null;
                    songLength = null;
                }
            }
            loaded = true;
        }
        catch (Exception e)
        {
            log.debug("Can't load .m3u playlist", e);
        }
        finally
        {
            try
            {
                if (br != null)
                {
                    br.close();
                }
            }
            catch (Exception ioe)
            {
                log.info("Can't close .m3u playlist", ioe);
            }
        }
        return loaded;
    }


Generated by  Doxygen 1.6.0   Back to index