title: Get duration of audio file on Android
body: <p>I fail at getting the duration of an in-bundle audio file on Android.</p>
  
  <p>I tried this:</p>
  
  <pre><code>        String stringDuration;
          MediaMetadataRetriever mmr = new MediaMetadataRetriever();
          try {
              mmr.setDataSource(fullpath);
              stringDuration = mmr.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
          }
          catch (IllegalArgumentException e) {
              debugalert("androidbridgeGetdurationofsound IllegalArgumentException error getting duration: " + e.getMessage());
              return 0;
          }
          catch (Exception e) {
              debugalert("androidbridgeGetdurationofsound Exception error getting duration: " + e.getMessage());
              return 0;
          }
          finally {
              mmr.release();
          }
  </code></pre>
  
  <p>It always fails with the IllegalArgumentException exception. I'm not sure if the path is incorrect (tried a few variants), the media is not supported (tried m4a and wav) by that MediaMetadataRetriever class or what. The audio itself plays fine on Android. </p>
  
  <p>A few path variants I tried are:</p>
  
  <ul>
  <li>assets/Assets/sounds/_TESTSOUNDWAVE.wav</li>
  <li>android.resource://com.package.name/assets/Assets/sounds/_TESTSOUNDWAVE.wav</li>
  </ul>
  
  <p>I am using Cocos2D-x v3.6. There is no inherent (working, afaik) way of getting the duration of audio files in there (tried using AudioEngine).
  The above code is from a static method on an activity called through JNI from the C++ side of Cocos2D-x.</p>