Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The short answer is no, you can't use <code>content://</code> as a source for an audio element.</p> <p>The error you are getting comes from the <code>HTML5Audio setDataSource</code> method, which if you look at the <a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.2.2_r1/android/webkit/HTML5Audio.java#HTML5Audio.setDataSource%28java.lang.String%29" rel="nofollow">source code</a>, calls <code>MediaPlayer setDataSource</code> with the audio url. And if you look at the <a href="http://developer.android.com/reference/android/media/MediaPlayer.html#setDataSource%28java.lang.String%29" rel="nofollow">documentation</a> for the <code>MediaPlayer</code> class, it only supports file paths and http/rtsp urls.</p> <p>I think your best bet is to save your audio content to a file path and use a <code>file:</code> url to access it.</p> <p>However, if I remember correctly, you will also need to make the file world readable in order for the <code>MediaPlayer</code> code to access it. This requires using the private <code>android.os.FileUtils</code> class with code like this:</p> <pre><code>void makeFileReadable(String filename) { try { Class fileUtils = Class.forName("android.os.FileUtils"); Method setPermissions = fileUtils.getMethod("setPermissions", String.class, int.class, int.class, int.class); setPermissions.invoke(fileUtils, filename, 0775, -1, -1); } catch (Exception ex) { } } </code></pre> <p><code>775</code> is the equivalent of <code>rwxrwxr-x</code> which may be more permissive than necessary, so you may want to try experimenting with less permissive values. Also note that you'll likely need to set the permissions on the directory containing the file, and that directory's parent, etc. - not just the file itself.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload