1

Sencha 触控控制器 JavaScript:

test:function(name)
{
    alert("function called");
    window.AndroidFunction.playAudio(name);
    alert("completed");
},

安卓JavaScript处理程序:

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());
    }
}
}

我从 sencha 触摸控制器功能调用 android 功能,但它不工作

4

1 回答 1

1

您是否尝试在模拟器或设备中运行您的应用程序。

就我而言,我试图在模拟器中运行它不工作,但在设备中它工作得很好。

于 2012-07-30T12:56:34.630 回答