Playing sound in WebView from JavaScript

后端 未结 3 737
庸人自扰
庸人自扰 2020-12-12 01:30

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(         


        
3条回答
  •  春和景丽
    2020-12-12 02:19

    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!

提交回复
热议问题