我有问题,我在webview上没有声音。 在Android上的原生浏览器上,声音正常工作。
声音是闪光灯。
如果您想查看,可以打开http://www.colourmonics.de/android/android16
这是我的剧本:
package C.K;
import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.webkit.WebChromeClient;
public class ColourmonicsKeyboardActivity extends Activity {
/** Called when the activity is first created. */
WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
setContentView(R.layout.main);
if (savedInstanceState != null){
((WebView)findViewById(R.id.webview)).restoreState(savedInstanceState);
} else {
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
mWebView.setWebChromeClient(new WebChromeClient());
mWebView.setWebViewClient(new MyWebViewClient());
mWebView.loadUrl("http://www.colourmonics.de/android/android16");
}
}
private AudioManager audio;
protected void onSaveInstanceState(Bundle outState) {
mWebView.saveState(outState);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
return true;
default:
return false;
}
}
}
谢谢
答案 0 :(得分:0)
我有类似的问题。我通过在我的webview中添加javascriptinterface来解决这个问题。然后调用一个在本机Java中播放声音的方法。