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;
}
}
Friday, 8 July 2011
Java Code Examples
Subscribe to:
Post Comments (Atom)
i like java but it is so hard!!!!!=D
ReplyDeleteSample code doesnt compile
ReplyDeletePlease can you separate out your MP3 encoder from your example file jump3r-1.0.3.jar
ReplyDeleteand post the library JAR and provide some documentation about how to use the library.
At the moment the only way to use your example jump3r-1.0.3.jar is to decompile it to try to extract the library component