0
你好,我正在編碼wav數據到android中的ogg vorbis。我爲Xiph.org的libogg-vorbis庫使用了一個簡單的JNI包裝器。當我創建的VorbisFileOutputStream
的對象,然後程序拋出exeception java.lang.UnsatisfiedLinkError: create
java.lang.UnsatisfiedLinkError:未找到本地方法:創建
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)
任何想法?
看看這篇文章:http://examples.javacodegeeks.com/java-basics/exceptions/java-lang- unsatisfiedlinkerror-how-to-handle-unsatisfied-link-error/ – ZaoTaoBao
@ZaoTaoBao我已經添加了* .so文件,請參閱截圖 – Mick