你好SO社區,android的webkit音頻工作4.1.2及以下,但不是以上?
我正在做一個應用程序的Android使用HTML和JS和Web視圖。該應用在按鈕點擊(html)上播放聲音。多謝你(這樣的人)我可以使它工作中使用此代碼:JAVA =
myJSInterface = new MyJSInterface(getApplicationContext());
webview.addJavascriptInterface(myJSInterface, "Android");
公共類MyJSInterface {
Context mcontext;
MediaPlayer mp;
MyJSInterface(Context c) {
mcontext = c;
}
public void MyAudioPlayer01(int audio) {
/** play sound from the web page */
if (issound) {
Integer[] soundid = { null, null, R.raw.s01, R.raw.s02,
R.raw.s28, null, null, R.raw.xdhiboun, };
if (soundid[audio] != null) {
mp = MediaPlayer.create(mcontext, soundid[audio]);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
mp = null;
}
});
}
}
}
我打電話通過JS上面的代碼:js代碼=
Android.MyAudioPlayer01(audio);
這適用於Android 4.1.2,但不是上面!
你能提出一些建議嗎(我一直在搜索整個一天)?
我也試過的Soundpool沒有運氣:-(
有什麼事情做JS和網頁流量安全更新?我是否需要添加更多的權限,新的Android版本?是媒體播放器過時了嗎?...
謝謝您的幫助