1
煎茶觸摸控制器的JavaScript:調用煎茶觸摸控制器的Android功能
test:function(name)
{
alert("function called");
window.AndroidFunction.playAudio(name);
alert("completed");
},
的Android JavaScriptHandler:
public class MyJavaScriptInterface {
Context mContext;
MediaPlayer mediaPlayer;
MyJavaScriptInterface(Context c) {
mContext = c;
}
public void playAudio(String path)
{
System.out.println("path "+path);
try {
int resID = mContext.getResources().getIdentifier(path, "raw", mContext.getPackageName());
if(mediaPlayer != null)
{
mediaPlayer.stop();
mediaPlayer.reset();
mediaPlayer.release();
mediaPlayer = null;
}
mediaPlayer = MediaPlayer.create(mContext, resID);
mediaPlayer.start();
} catch (Exception e) {
System.out.println("ERROR in Play Audio : " + e.getMessage());
}
}
}
IM呼籲從煎茶觸摸控制器功能 但它不工作的Android功能