I am trying to create methods that would fastforward and rewind an mp3. I have methods that would play stop and pause, but the ff and rewind ones are giving me problems. I was thinking of doing it this way somehow:
to fast forward
play mp3 at "currentFrame +100"
I am just having trouble getting the current frame for the mp3. Below is what I have so far in terms of code for controlling the mp3. I am using jLayer and jAudioTagger(for grabbing the mp3 tags)
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package i_hope_this_works;
public mp3_player(String namer) throws UnsupportedAudioFileException, IOException, JavaLayerException {
this.mp3Name = namer;
File mp3_file = new File(mp3Name);
filename = namer;
infoManager infoM = new infoManager(this.filename);
try {
FileInputStream fis = new FileInputStream(filename);
// The MPEG bitstream
BufferedInputStream bis = new BufferedInputStream(fis);
player = new AdvancedPlayer(bis);
/**
* @return the e
*/
public Exception getE() {
Exception e = null;
return e;
}
/**
* @param e the e to set
*/
private class AdvancedPlayerThread extends Thread {
//need a run method, will be called when the thread is 'started'
public void run() {
try {
System.out.println("Starting track at frame " + trackStart
+ " until frame " + trackEnd);
player.play(trackStart, trackEnd);
} catch (Exception e) {
System.out.println(e);
}
if (closeOnFinish) {
System.exit(0);
}
}
}
/**
* Extends the existing JLayer PlaybackListener class, so it
* prints the number of milliseconds expired when we stop a
* track
*/
public class MyListener extends PlaybackListener {
public void playbackFinished(PlaybackEvent evt) {
// It seems, on viewing the JLayer code, that the getFrame method in
// the PlaybackEvent actually returns milliseconds transpired not frames.
System.out.println("Milliseconds elapsed in track: " + evt.getFrame());
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package i_hope_this_works;
public String getPlayingTime() {
String playtime = fil.getPlayingTimeString();
return playtime;
}
//checks to see if the file is a MP3
public boolean isMP3() {
return fil.isMP3();
}
//checks if the file has ID3v1 tags
/*
* What you would do is to FIRST check if the file has tags and THEN
* Get theinformation
*/
public boolean ID3v1exist() {
return fil.id3v1Exists();
}
//checks if the file has ID3v2 tags
public boolean ID3v2exist() {
return fil.id3v2Exists();
}
public void setArtist(String artist) throws FileNotFoundException, IOException {
fil.setArtist(artist);
fil.writeTags();
Bookmarks