尝试获取bitRate,sampleRate,channelCount

时间:2015-10-13 07:33:51

标签: java android audio sample-rate

我想获得一个音频文件的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

1 个答案:

答案 0 :(得分:1)

  

无法打开libwvm.so:dlopen失败:library" libwvm.so"不   结果

表示运行代码的设备没有该库。您可以尝试编译自己的First_part = "=(" and Last_Part = ")"版本并将其引入。抛出异常后,First_part = "=IF(F1=2;" and Last_Part = ";0)"返回空引用,Sub Adding_IFERROR() Dim Cell_Content As String Dim First_Part As String Dim Last_Part As String Dim New_Cell_Content As String First_Part = "=IFERROR(" Last_Part = ";0)" 'Remove the initial "=" sign from original formula Cell_Content = ActiveCell.Formula Cell_Content = Right(Cell_Content, Len(Cell_Content) - 1) 'Writing new formula New_Cell_Content = First_Part & Cell_Content & Last_Part MsgBox New_Cell_Content, vbOKOnly ActiveCell.Formula = New_Cell_Content End Sub 使libwvm.so的应用崩溃}。为了避免崩溃,您可以在打印异常的堆栈跟踪后返回。 E.g。

mex.getTrackFormat(0);