Need to search ogg using Java
I am working on a multi-platform desktop application that needs to implement both mp3 and ogg player including search. Now my mp3 part is ok, but searching in ogg game doesn't work ...
I am using BasicPlayer
for javazoom.jlgui and the following search function
/**
* Skip bytes in the File inputstream. It will skip N frames matching to
* bytes, so it will never skip given bytes length exactly.
*
* @param bytes
* @return value>0 for File and value=0 for URL and InputStream
* @throws BasicPlayerException
* @throws IOException
*/
protected long skipBytes(long bytes) throws BasicPlayerException, NullPointerException, IOException {
long totalSkipped = 0;
if (m_dataSource instanceof File) {
log.info("Bytes to skip : " + bytes);
int previousStatus = m_status;
m_status = SEEKING;
long skipped = 0;
synchronized (m_audioInputStream) {
notifyEvent(BasicPlayerEvent.SEEKING, getEncodedStreamPosition(), -1, null);
initAudioInputStream();
if (m_audioInputStream != null) {
// Loop until bytes are really skipped.
while (totalSkipped < (bytes - SKIP_INACCURACY_SIZE)) {
skipped = m_audioInputStream.skip(bytes - totalSkipped);
if (skipped == 0) {
break;
}
totalSkipped = totalSkipped + skipped;
log.info("Skipped : " + totalSkipped + "/" + bytes);
if (totalSkipped == -1) {
throw new BasicPlayerException(BasicPlayerException.SKIPNOTSUPPORTED);
}
}
}
}
notifyEvent(BasicPlayerEvent.SEEKED, getEncodedStreamPosition(), -1, null);
m_status = OPENED;
if (previousStatus == PLAYING) {
startPlayback();
} else if (previousStatus == PAUSED) {
startPlayback();
pausePlayback();
}
}
return totalSkipped;
}
Is there a way to add another search function to implement seek for ogg? thanks in advance...
Don't know much about how this works, but it works great for mp3, including search, play audio, pause, stop In ogg games, pause, stop are fine, but searching is a problem when searching for a sound starts from the beginning.
I have not modified some of the code the source of the BasicPlayer Api is http://www.javazoom.net/jlgui/sources/basicplayer3.0.zip
When I checked the details in detail, the jlgui3.0 player implemented using this code is also not implemented looking for the Ogg game, they mentioned it. So the current code should be added with a separate search function for Ogg playback and use it instead of the current seek()
one when the playback sound is Ogg ...
I don't know how to do this, help me with a good source for a link and an easy way to implement the same ...
source to share
I think this library may not be enough for your needs. Looking at the jlGui source code (pasted below) search is only supported for .mp3 and .wav files.
Also, the logic behind it is somewhat naive because it only jumps a fixed number of bytes. For .wav files of PCM format, the number of bytes skipped will always be proportional to the number of skips skipped, but for variable speed .mp3 files, the amount of time you miss will differ from the instant bitrate at different points in the file, Ogg Vorbis is a container format that supports multiplexing, which makes searching more difficult than just jumping ahead in the file and re-synchronizing the decoder.
Alternatively, I would recommend using the JavaSound or JavaFX API, which can play audio files and look for the time you provide, not the byte offset.
From jlGui:
protected void processSeek(double rate)
{
try
{
if ((audioInfo != null) && (audioInfo.containsKey("audio.type")))
{
String type = (String) audioInfo.get("audio.type");
// Seek support for MP3.
if ((type.equalsIgnoreCase("mp3")) && (audioInfo.containsKey("audio.length.bytes")))
{
long skipBytes = (long) Math.round(((Integer) audioInfo.get("audio.length.bytes")).intValue() * rate);
log.debug("Seek value (MP3) : " + skipBytes);
theSoundPlayer.seek(skipBytes);
}
// Seek support for WAV.
else if ((type.equalsIgnoreCase("wave")) && (audioInfo.containsKey("audio.length.bytes")))
{
long skipBytes = (long) Math.round(((Integer) audioInfo.get("audio.length.bytes")).intValue() * rate);
log.debug("Seek value (WAVE) : " + skipBytes);
theSoundPlayer.seek(skipBytes);
}
else posValueJump = false;
}
else posValueJump = false;
}
catch (BasicPlayerException ioe)
{
log.error("Cannot skip", ioe);
posValueJump = false;
}
}
source to share