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
Would this work for you?
mWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.endsWith(".ogg")){
Log.d(TAG, "Reproducir archivo OGG");
Uri tempPath = Uri.parse(url);
MediaPlayer player = MediaPlayer.create(WebViewVideo.this, tempPath);
player.start();
return true;
}else{
return super.shouldOverrideUrlLoading(view, url);
}
}
});
If you really want to use Javascript, you can try with document.open() or something like that, I haven't tried so, but I guess it would work the same way.
By the way, this is the case that you want to play that audio on background, if you want to show the actual player, I think you have to implement the View by yourself.
And if you were considering html5 audio tag, forget it. AFAIK Froyo doesn't support it in any way.
I hope this helps and it's not too late.
Regards.
Play around with this:
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);