您好,我正在将 wav 数据编码到 android 中的 ogg vorbis 中。我正在使用来自 Xiph.org 的 libogg-vorbis 库的简单 JNI 包装器。当我创建VorbisFileOutputStream
然后程序抛出异常 的对象时java.lang.UnsatisfiedLinkError: create
VorbisFileOutputStream.java
public class VorbisFileOutputStream extends AudioOutputStream {
// The index into native memory where the ogg stream info is stored.
private final int oggStreamIdx;
private VorbisInfo info;
private static final int VORBIS_BLOCK_SIZE = 1024;
static {
System.loadLibrary("ogg");
System.loadLibrary("vorbis");
System.loadLibrary("vorbis-stream");
}
public VorbisFileOutputStream (String fname, VorbisInfo s) throws IOException {
info = s;
oggStreamIdx = this.create(fname, s);
}
public VorbisFileOutputStream (String fname) throws IOException {
oggStreamIdx = this.create(fname, new VorbisInfo());
}
@Override
public void close() throws IOException {
this.closeStreamIdx(this.oggStreamIdx);
}
/**
* Write PCM data to ogg. This assumes that you pass your streams in interleaved.
* @param buffer
* @param offset
* @param length
* @return
* @throws java.io.IOException
*/
@Override
public void write(final short [] buffer, int offset, int length) throws IOException {
this.writeStreamIdx(this.oggStreamIdx, buffer, offset, length);
}
private native int writeStreamIdx(int idx, short [] pcmdata, int offset, int size) throws IOException;
private native void closeStreamIdx(int idx) throws IOException;
private native int create(String path, VorbisInfo s) throws IOException;
@Override
public int getSampleRate() {
return info.sampleRate;
}
}
MainActivity.java
try {
vorbisFileOutputStream = new VorbisFileOutputStream(
"/sdcard/demo.ogg");
} catch (IOException e) {
e.printStackTrace();
}
while (isRecording) {
// gets the voice output from microphone to byte format
recorder.read(sData, 0, bufferSize / 2);
System.out.println("Short writing to file" + sData.toString());
try {
// writes the data to file from buffer stores the voice buffer
dataOutputStream.write(short2byte(sData));
vorbisFileOutputStream.write(short2byte(sData));
} catch (IOException e) {
e.printStackTrace();
}
}
错误日志:
04-15 16:04:00.515: E/AndroidRuntime(2299): FATAL EXCEPTION: AudioRecorder Thread
04-15 16:04:00.515: E/AndroidRuntime(2299): java.lang.UnsatisfiedLinkError: create
04-15 16:04:00.515: E/AndroidRuntime(2299): at com.example.app.VorbisFileOutputStream.create(Native Method)
04-15 16:04:00.515: E/AndroidRuntime(2299): at com.example.app.VorbisFileOutputStream.<init>(VorbisFileOutputStream.java:33)
04-15 16:04:00.515: E/AndroidRuntime(2299): at com.example.app.MainActivity.writeAudioDataToFile(MainActivity.java:111)
04-15 16:04:00.515: E/AndroidRuntime(2299): at com.example.app.MainActivity.access$0(MainActivity.java:93)
04-15 16:04:00.515: E/AndroidRuntime(2299): at com.example.app.MainActivity$1.run(MainActivity.java:48)
04-15 16:04:00.515: E/AndroidRuntime(2299): at java.lang.Thread.run(Thread.java:1019)
任何想法 ??