sb.append("}");
String mediaOptions = sb.toString();
final MediaPlayerFactory factory = new MediaPlayerFactory();
final HeadlessMediaPlayer mediaPlayer = factory.newHeadlessMediaPlayer();
mediaPlayer.addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
DecimalFormat df = new DecimalFormat("0.00");
@Override
public void playing(MediaPlayer mediaPlayer) {
System.out.println("Playing...");
}
@Override
public void positionChanged(MediaPlayer mediaPlayer, float newPosition) {
// This escape sequence to reset the terminal window cursor back to
// column zero will not work in the Eclipse console window and most
// likely not work on Windows at all
System.out.print(df.format(newPosition * 100.0f) + "%" + "\u001b[0G");
}
@Override
public void finished(MediaPlayer mediaPlayer) {
System.out.println();
System.out.println("Finished.");
mediaPlayer.release();
factory.release();
try {
// Probably not required, but just in case there are any pending
// native buffers
Thread.sleep(1000);
}
catch(InterruptedException e) {
}
System.exit(0);
}
@Override
public void error(MediaPlayer mediaPlayer) {
System.out.println();
System.out.println("Error.");
mediaPlayer.release();
factory.release();
System.exit(1);
}
});
System.out.println(" MRL: " + mrl);
System.out.println("Media Options: " + mediaOptions);
mediaPlayer.prepareMedia(mrl, mediaOptions);
boolean started = mediaPlayer.start();
if(!started) {
System.out.println("Failed to start");
System.exit(1);
}