2015-10-13 44 views
-1

我想比特率,採樣率,一個音頻文件嘗試獲得比特率,採樣率,信道計數

我使用代碼

@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

未能打開libwvm.so:dlopen的失敗:庫 「libwvm.so」 不 發現

意味着你在哪裏運行你的代碼,設備沒有這個庫。您可以嘗試編譯自己的libwvm.so版本並將其引入。除了拋出的異常,mex.getTrackFormat(0);返回了空引用,mf.getInteger(正在使您的應用崩潰爲NPE。爲了避免在打印異常的堆棧跟蹤後可能返回的崩潰。例如。

catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
     return; 
    } 
+0

感謝您的回覆。但我怎麼能libwvm.so我搜索這個,但找不到任何東西 –