gpt4 book ai didi

java - 尝试获取bitRate,sampleRate,channelCount

转载 作者:行者123 更新时间:2023-12-03 02:30:44 24 4
gpt4 key购买 nike

我想获取一个音频文件的bitRate,sampleRate,channelCount

我使用代码

@SuppressLint("NewApi")
public void GetSampleRate(String path)
{
MediaExtractor mex = new MediaExtractor();
try {
mex.setDataSource(new File(path).getAbsolutePath());// the adresss location of the sound on sdcard.
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

MediaFormat mf = mex.getTrackFormat(0);

bitRate = mf.getInteger(MediaFormat.KEY_BIT_RATE);
sampleRate = mf.getInteger(MediaFormat.KEY_SAMPLE_RATE);
channelCount = mf.getInteger(MediaFormat.KEY_CHANNEL_COUNT);

}

但是当编译器出现在这一行时
mex.setDataSource(new File(path).getAbsolutePath());

logcat显示一个错误
10-13 12:57:52.772: E/WVMExtractor(9554): Failed to open libwvm.so: dlopen failed: library "libwvm.so" not found

然后当我尝试获取bitRate,sampleRate,channelCount时出现此错误。
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference

最佳答案

Failed to open libwvm.so: dlopen failed: library "libwvm.so" not found



表示您正在运行代码的设备没有该库。您可以尝试编译自己的 libwvm.so版本并将其引入。除了引发异常外, mex.getTrackFormat(0);返回空引用,而 mf.getInteger(使 NPE崩溃。为避免崩溃,您可以在打印异常的堆栈跟踪后返回。例如。
    catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}

关于java - 尝试获取bitRate,sampleRate,channelCount,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33096709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com