我想很快端口与上播放声音(与soundmanager2)HTML应用程序中使用的WebView一个原生的Android应用程序。从我的研究,我还没有看到任何证据表明,声音,如MP3音乐,可以通过JavaScript或使用的WebView任何其他方式进行播放。
I'm trying to very quickly port over an html application with plays sound (with soundmanager2) to a native android app using WebView. From my research, I haven't seen any evidence that sound, such as mp3s, can be played via javascript or any other methods using WebView.
我现在的目标是快速端口上的HTML应用程序,并最终建立一个忠实地原生应用程序,而无需使用WebViews。
My goal now is to quickly port over the html app and then eventually create a truely native application without using WebViews.
请让我知道是否有人已经能够成功地实现播放使用WebViews和Javascript的音频或者如果这是不可能的,在这个时候。
Please let me know if anyone has been able to successfully implement playing audio using WebViews and Javascript or if this is just not possible at this time.
感谢你。
玩弄这样的:
if(cm.message().contains("play sound")) {
//String[] temp = cm.message().split("#");
AudioManager audiomanager= (AudioManager) getSystemService(AUDIO_SERVICE);
float actualvolume = (float) audiomanager.getStreamVolume (AudioManager.STREAM_MUSIC);
float maxVolume= (float) audiomanager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = actualvolume/maxVolume;
if (loaded) {
soundPool.play(soundID, volume, volume, 1, 54, 1f);
Log.e("Test", "Played sound");
}
} else if(cm.message().contains("stop sound")) {
soundPool.stop(1);
Log.e("Test","stoped");
}
myWebView.loadUrl("file:///android_asset/timer.html");
soundID = soundPool.load(this, R.raw.sound1,1);