-1

i want to get bitRate, sampleRate,channelCount of one audio file

i use code

@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);

    }

But when compiler come on this line

mex.setDataSource(new File(path).getAbsolutePath());

logcat show one error

10-13 12:57:52.772: E/WVMExtractor(9554): Failed to open libwvm.so: dlopen failed: library "libwvm.so" not found

and then this error when i try to get bitRate, sampleRate,channelCount.

java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference
Bhanu Sharma
  • 5,135
  • 2
  • 24
  • 49

1 Answers1

1

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

means that device where you are running your code has not that library. You could try to compile your own version of libwvm.so and bring it in. With the exception thrown, mex.getTrackFormat(0); is returning a null reference and mf.getInteger( is making your app crash for NPE. To avoid the crash you could return after printing the stacktrace of the exception. E.g.

    catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return;
    }
Blackbelt
  • 156,034
  • 29
  • 297
  • 305
  • Thanks For Reply. But how can i get libwvm.so i search for this but couldn't found anything – Bhanu Sharma Oct 13 '15 at 07:57
  • But running DRM Info on my Moto G5 does say that Widevine CDM is there. Also, getTrackFormat(0) etc. all work perfectly. Yet I still have this error. – mavavilj Dec 09 '22 at 16:06