Changes
Simple UI to encode/decode mp3 files.
Download
Pure Java MP3 Encoder
Saturday, 9 July 2011
Friday, 8 July 2011
Java Code Examples
package test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import org.jma.DataType;
import org.jma.encoder.IEncoder;
import org.jma.encoder.audio.IAudioEncoder;
import test.TestClass;
import com.sswf.rtmp.Consumer;
public class CaptureAudio implements Runnable {
private ByteArrayOutputStream outputStream;
private boolean running;
private TestClass line;
private IAudioEncoder audioEncoder;
private Consumer consumer;
public CaptureAudio(ByteArrayOutputStream outputStream, TestClass line, IEncoder encoder) {
this.outputStream = outputStream;
this.line = line;
this.audioEncoder = encoder.getAudioEncoder();
}
public CaptureAudio(Consumer consumer, TestClass line) {
this.consumer = consumer;
this.line = line;
this.audioEncoder = consumer.getEncoder().getAudioEncoder();
}
public CaptureAudio(ByteArrayOutputStream outputStream, Consumer consumer, TestClass line) {
this.outputStream = outputStream;
this.consumer = consumer;
this.line = line;
this.audioEncoder = consumer.getEncoder().getAudioEncoder();
}
public void run() {
running = true;
int bufferSize = audioEncoder.getInputBufferSize();
byte buffer[] = new byte[bufferSize];
byte[] encoded = new byte[audioEncoder.getOutputBufferSize()];
try {
while (running) {
int count = line.read(buffer, 0, buffer.length);
if (count > 0) {
int encodedCount = audioEncoder.encodeBuffer(buffer, 0, count, encoded);
//encoded mp3 bytes
if (outputStream != null)
//outputStream.write(buffer, 0, count);
outputStream.write(encoded, 0, encodedCount);
if (consumer != null)
consumer.putData(DataType.AUDIO, System.currentTimeMillis(), encoded, encodedCount);
}
}
int encodedCount = audioEncoder.encodeFinish(encoded);
if (outputStream != null)
outputStream.write(encoded, 0, encodedCount);
if (consumer != null)
consumer.putData(DataType.AUDIO, System.currentTimeMillis(), encoded,
encodedCount);
audioEncoder.close();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public synchronized void setRunning(boolean running){
this.running = running;
}
}
Release 1.0.1
Pure Java MP3 Encoder. Ideal solution for a built-in MP3 encoder library.
Supported source formats:
- WAVE_FORMAT_PCM
- WAVE_FORMAT_IEEE_FLOAT 32bit per sample only
For more detailed information about the source encoding please review Wav Format Spec
Download
Supported source formats:
- WAVE_FORMAT_PCM
- WAVE_FORMAT_IEEE_FLOAT 32bit per sample only
For more detailed information about the source encoding please review Wav Format Spec
Download
Subscribe to:
Posts (Atom)