/* BlinkenSim
 * version 0.1 date 2006-07-28
 * Copyright (C) 2004-2006: Stefan Schuermans <1stein@schuermans.info>
 * Copyleft: GNU public license - http://www.gnu.org/copyleft/gpl.html
 * a blinkenarea.org project
 */

package org.blinkenarea.BlinkenSim;

import java.applet.*;
import java.io.*;
import java.net.*;

public class PlaylistPlayer extends MoviePlayer {

  public PlaylistPlayer( Applet applet ) {

    String playlistName = applet.getParameter( "playlist" );
    if( playlistName == null || playlistName.length( ) <= 0 )
      playlistName = "playlist";

    try {

      URL base = applet.getDocumentBase( );
      URL url;
      if( base != null ) {
        url = new URL( base, playlistName );
      } else {
        url = new URL( "file:" + playlistName );
      }

      BufferedReader reader = new BufferedReader( new InputStreamReader( url.openStream( ) ) );

      int len = 16, cnt = 0;
      String [] names = new String [len];
      try {
        while( true ) {
          String line = reader.readLine( );
          if( line == null )
            break;
          names[cnt++] = line;
          if( cnt >= len ) {
			len *= 2;
            String [] newNames = new String [len];
            for( int i = 0; i < cnt; i++ )
              newNames[i] = names[i];
            names = newNames;
          }
        }
      } catch( IOException e ) {
      }

      String [] movieNames = new String [cnt];
      for( int i = 0; i < cnt; i++ )
        movieNames[i] = names[i];
      setUp( applet, movieNames );

    } catch( MalformedURLException e ) {
    } catch( IOException e ) {
    }

  }

} // class PlaylistPlayer
