{
String dataSourceClassName = (String) dataSourceList.get(i);
try
{
final Class<?> dataSourceClass = Class.forName(dataSourceClassName);
final DataSource dataSource = (DataSource) dataSourceClass.newInstance();
dataSource.setLocator(sourceLocator);
dataSource.connect();
return createPlayer(dataSource);
// TODO: JMF seems to disconnect data sources in this method, based on this stack trace:
// java.lang.NullPointerException
// at com.sun.media.protocol.rtp.DataSource.disconnect(DataSource.java:207)
// at javax.media.Manager.createPlayer(Manager.java:425)
// at net.sf.fmj.ui.application.ContainerPlayer.createNewPlayer(ContainerPlayer.java:357)
}
catch (NoPlayerException e)
{ // no need to log, will be logged by call to createPlayer.
continue;
}
catch (ClassNotFoundException e)
{
logger.warning("createPlayer: " + e); // no need for call stack
continue;
}
catch (IOException e)
{
logger.log(Level.WARNING, "" + e, e);
continue;
}
catch (NoClassDefFoundError e)
{
logger.log(Level.WARNING, "" + e, e);
continue;
}
catch (Exception e)
{
logger.log(Level.WARNING, "" + e, e);
continue;
}
}
// if none found, try URLDataSource:
final URL url;
try
{
url = sourceLocator.getURL();
}
catch (Exception e)
{ logger.log(Level.WARNING, "" + e, e);
throw new NoPlayerException();
}
final URLDataSource dataSource = new URLDataSource(url);
dataSource.connect(); // TODO: there is a problem because we connect to the datasource here, but
// the following call may try twice or more to use the datasource with a player, once
// for the right content type, and multiple times for unknown. The first attempt (for example) may actually
// read data, in which case the second one will be missing data when it reads.
// really, the datasource needs to be recreated.
// The workaround for now is that URLDataSource (and others) allows repeated connect() calls.