I\'m trying to play sound from JavaScript code loaded to WebView from assets:
WebView web_view = (WebView) findViewById(R.id.web_view);
web_view.getSettings(
It depends on your Android device and the available codecs... But probably the path is not correct. Are you using Phonegap? Does your code play on desktop browsers?
I'm using a similar code:
var myAudio = document.getElementsByTagName('audio')[0];
myAudio.pause();
myAudio.src = file;
myAudio.play();
And my HTML audio tag is this:
<audio id="audio" src="" type="audio/mpeg" preload="metadata" ontimeupdate="timeUpdate()"
ondurationchange="durationChange()" onerror="musicError()" onended="musicEnded()">
<embed src="" height=50 width=100></embed>
I'm using mp3 audio file format because it works for iOS and some Android devices.
Also, notice that Audio tag element is not available on all android versions. As you can see here, it works for Android 2.3 and up.
I had the same problem and finally i'm using phonegap and cordova where you can play and record audios easily: http://docs.phonegap.com/en/2.9.0/cordova_media_media.md.html
Re: MediaPlayer( ): Error (1,-2147483648)
The Android MediaPlayer needs the media files to be world-readable so they can’t reside in the “assets” folder inside the Eclipse project. Push the audio/video files onto the device external storage. To do this, with an emulator, use the DDMS Perspective in Eclipse (while your emulator is running go to Window->Open Prospective->Other->DDMS) to create a folder and push files onto SD card image or internal (non-removable) storage.
Reference on DDMS: http://developer.android.com/guide/developing/debugging/ddms.html
In DDMs, select your emulator in the Devices panel on the left, and then choose the FileExplorer tab on the right, look for a folder named /mnt/sdcard/ which contains the SDCard contents, or, alternatively /Android/data/package_name/files/ for the standardized application’s storage area. So, in the above example, if you create a folder myaudio on the SDcard the filename path would be:
audio = new Audio("/mnt/sdcard/myaudio/sound.mp3");
Reference: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
And don't give up on HTML5!