
com.neuronrobotics.sdk.dyio.sequencer.SequencerMP3 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-bowler Show documentation
Show all versions of java-bowler Show documentation
A command line utility for accesing the bowler framework.
The newest version!
package com.neuronrobotics.sdk.dyio.sequencer;
/*************************************************************************
* Compilation: javac -classpath .:jl1.0.jar MP3.java (OS X)
* javac -classpath .;jl1.0.jar MP3.java (Windows)
* Execution: java -classpath .:jl1.0.jar MP3 filename.mp3 (OS X / Linux)
* java -classpath .;jl1.0.jar MP3 filename.mp3 (Windows)
*
* Plays an MP3 file using the JLayer MP3 library.
*
* Reference: http://www.javazoom.net/javalayer/sources.html
*
*
* To execute, get the file jl1.0.jar from the website above or from
*
* http://www.cs.princeton.edu/introcs/24inout/jl1.0.jar
*
* and put it in your working directory with this file MP3.java.
*
*************************************************************************/
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import com.neuronrobotics.sdk.addons.kinematics.JavaFXInitializer;
import com.neuronrobotics.sdk.util.ThreadUtil;
//import javafx.embed.swing.JFXPanel;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.stage.Stage;
import javafx.util.Duration;
// TODO: Auto-generated Javadoc
/**
* The Class SequencerMP3.
*/
public class SequencerMP3 {
/** The fn. */
private String fn="";
/** The player. */
// constructor that takes the name of an MP3 file
private MediaPlayer player;
/** The track length. */
private int trackLength = 37;
/**
* Instantiates a new sequencer m p3.
*
* @param filename the filename
*/
static{
JavaFXInitializer.go();
}
public SequencerMP3(String filename) {
fn = filename;
try {
player = new MediaPlayer(
new Media(
new File(fn).toURI().toString()));
while(player.getStatus() != MediaPlayer.Status.READY){ThreadUtil.wait(200);}
trackLength =(int) player.getCycleDuration().toMillis();
player.setOnStopped(new Runnable() {
@Override
public void run() {
// pause=true;
}
});
}
catch (Exception e) {
System.out.println("Problem playing file " + filename+"\r\n");
//e.printStackTrace();
throw new RuntimeException(e);
}
}
/**
* Pause.
*/
public void pause(){
player.pause();
}
/**
* Close.
*/
public void close() {
if (player != null)
player.stop();
}
/**
* Checks if is playing.
*
* @return true, if is playing
*/
public boolean isPlaying() {
if(player!=null)
return (player.getCurrentTime().toMillis()
© 2015 - 2025 Weber Informatics LLC | Privacy Policy