I've experimented with 3 approaches to addressing this problem, each of which is a variation of the others, and each involve copying the original audio files from the internal "assets" directory (apparently not accessible to the default MediaPlayer) to a directory which can be accessed. The various target directories are described at link:
http://developer.android.com/guide/topics/data/data-storage.html
of which these three were used:
- internal storage [ /data/data/your.package.name/files; ie. context.getFilesDir() ]
- external application storage [ /mnt/sdcard/Android/data/package_name/files/Music; ie. context.getExternalFilesDir(null) ]
- external general storage [ /mnt/sdcard/temp; ie. Environment.getExternalStorageDirectory() + "/temp" ]
In all cases, the files were assigned "world readable" privileges to make them accessible to the default MediaPlayer. The first approach (internal) is preferred because the files are incorporated as part of the package itself and can be removed from the "Clear data" option through the device's "Manage Apps" application and are automatically removed when the application is uninstalled. The second approach is similar to the first, but the files are only removed when the application is uninstalled, is dependent on external storage, and requires privileges to write to external storage specified in the manifest. The third approach is the least favourable; it is similar to the second, but there is no cleanup of the audio files when the application is uninstalled. Two tags were provided for each tag, the first uses the Android path, and the second uses the original path so that the HTML files can be examined through a Chrome browser before being incorporated in the Android App.
Internal Storage Solution
Java Code
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
localBrowser = (WebView)findViewById(R.id.localbrowser);
localBrowser.getSettings().setJavaScriptEnabled(true);
localBrowser.setWebViewClient(new WebViewClient());
localBrowser.setWebChromeClient(new WebChromeClient());
...
Context context = localBrowser.getContext();
File filesDir = context.getFilesDir();
Log.d("FILE PATH", filesDir.getAbsolutePath());
if (filesDir.exists())
{
filesDir.setReadable(true, false);
try
{
String[] audioFiles = context.getAssets().list("audio");
if (audioFiles != null)
{
byte[] buffer;
int length;
InputStream inStream;
FileOutputStream outStream;
for (int i=0; i<audioFiles.length; i++)
{
inStream = context.getAssets().open(
"audio/" + audioFiles[i] );
outStream = context.openFileOutput(audioFiles[i],
Context.MODE_WORLD_READABLE);
buffer = new byte[8192];
while ((length=inStream.read(buffer)) > 0)
{
outStream.write(buffer, 0, length);
}
// Close the streams
inStream.close();
outStream.flush();
outStream.close();
}
}
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Feedback
String[] fileList = context().fileList();
Log.d("FILE LIST", "--------------");
for (String fileName : fileList)
{
Log.d("- FILE", fileName);
}
...
}
Corresponding HTML Tags
<div id="centre_all" style="width:300px;height:400px;">
<audio controls="controls" autoplay="autoplay">
<source src="/data/data/com.test.audiotag/files/a-00099954.mp3" type="audio/mpeg" />
<source src="audio/a-00099954.mp3" type="audio/mpeg" />
 
</audio>
</div>
External General Storage Solution
With this solution, attempted to use "onDestroy()" method to cleanup temporary files copied to "/mnt/sdcard/temp" directory when done but in practise, the method never seemed to executed (tried both "onStop()" and "onPause()" which were called, but they prematurely removed the files). A discussion of "onDestroy()" given here confirms that it's code may not execute:
http://developer.android.com/reference/android/app/Activity.html#onDestroy()
Manifest Entry
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Java Code
private String[] audioList;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
localBrowser = (WebView)findViewById(R.id.localbrowser);
localBrowser.getSettings().setJavaScriptEnabled(true);
localBrowser.setWebViewClient(new WebViewClient());
localBrowser.setWebChromeClient(new WebChromeClient());
...
Context context = localBrowser.getContext();
File dirRoot = new File(Environment.getExternalStorageDirectory().toString());
Log.d("ROOT DIR PATH", dirRoot.getAbsolutePath());
if (dirRoot.exists())
{
File dirTemp = new File(dirRoot.getAbsolutePath() + "/temp");
if (!dirTemp.exists())
{
if (!dirTemp.mkdir())
{
Log.e("AUDIO DIR PATH", "FAILED TO CREATE " +
dirTemp.getAbsolutePath());
}
}
else
{
Log.d("AUDIO DIR PATH", dirTemp.getAbsolutePath());
}
if (dirTemp.exists())
{
dirTemp.setReadable(true, false);
dirTemp.setWritable(true);
try
{
String[] audioFiles = context.getAssets().list("audio");
if (audioFiles != null)
{
byte[] buffer;
int length;
InputStream inStream;
FileOutputStream outStream;
audioList = new String[audioFiles.length];
for (int i=0; i<audioFiles.length; i++)
{
inStream = context.getAssets().open(
"audio/" + audioFiles[i] );
audioList[i] = dirTemp.getAbsolutePath() + "/" +
audioFiles[i];
outStream = new FileOutputStream(audioList[i]);
buffer = new byte[8192];
while ( (length=inStream.read(buffer)) > 0)
{
outStream.write(buffer, 0, length);
}
// Close the streams
inStream.close();
outStream.flush();
outStream.close();
//audioFile = new File(audioList[i]);
//audioFile.deleteOnExit();
}
}
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// Feedback
String[] fileList = dirTemp.list();
Log.d("FILE LIST", "--------------");
for (String fileName : fileList)
{
Log.d("- FILE", fileName);
}
}
...
} // onCreate()
@Override
public void onDestroy()
{
for (String audioFile : audioList)
{
File hFile = new File(audioFile);
if (hFile.delete())
{
Log.d("DELETE FILE", audioFile);
}
else
{
Log.d("DELETE FILE FAILED", audioFile);
}
}
super.onDestroy();
} // onDestroy()
Corresponding HTML Tags
<div id="centre_all" style="width:300px;height:400px;">
<audio controls="controls" autoplay="autoplay">
<source src="/mnt/sdcard/temp/a-00099954.mp3" type="audio/mpeg" />
<source src="audio/a-00099954.mp3" type="audio/mpeg" />
 
</audio>
</div>
External Application Storage Solution
I won't list the code here, but it's essentially a blend of the solutions shown above. Note that Android must look at the file extensions and decide where to store the files; whether you specify directory "context.getExternalFilesDir(null)" or "context.getExternalFilesDir(Environment.DIRECTORY_MUSIC)", in both cases, the files will be written to directory "/mnt/sdcard/Android/data/package_name/files/Music".
Final Comments
While the above approach works, there are shortcomings. First, the same data is duplicated and therefore doubles the storage space. Second, the same MediaPlayer is used for all sound files so the playing of one will interrupt its predecessor which prevents being able to play background audio over which separate foreground audio is played. When I experimented with the solution described here, I was able to play multiple audio files simultaneously:
Android: Playing an Asset Sound Using WebView
I think a better solution would be one that uses a Javascript function to launch the audio that in turn calls an Android Java method that starts its own MediaPlayer (I may eventually experiment with that).