我正在尝试调用一个函数来阻止另一个类的谷歌 VR 播放器。但是每次我得到这个错误时:
Attempt to invoke virtual method 'void com.thevrplugin.cordovapluginvrplayer.MediaLoader.pause()' on a null object reference
我认为我以错误的方式调用它,你会怎么做?也许这只是私有/公共/受保护的修饰符混乱?附言。你可以在这里找到演示项目:https ://github.com/StarStep/cordova-vr-help.git
所以具有功能的类是这样的:
package com.thevrplugin.cordovapluginvrplayer;
...
public class VrVideoActivity extends GvrActivity {
private static final String TAG = "VrVideoActivity";
private static final int EXIT_FROM_VR_REQUEST_CODE = 42;
private GvrView gvrView;
private Renderer renderer;
private VideoUiView uiView;
protected MediaLoader mediaLoader;
private ControllerManager controllerManager;
private Controller controller;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mediaLoader = new MediaLoader(this);
gvrView = new GvrView(this);
gvrView.setRenderTargetScale(.5f);
renderer = new Renderer(gvrView);
gvrView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
gvrView.setRenderer(renderer);
setContentView(gvrView);
}
@Override
protected void onNewIntent(Intent intent) {
setIntent(intent);
recreate();
}
@Override
protected void onPause() {
mediaLoader.pause();
controllerManager.stop();
super.onPause();
}
}
然后从这里调用它
public class VrPlayer extends CordovaPlugin {
private String play(Context context, JSONArray args) throws JSONException {
Intent intent = new Intent(context, VrVideoActivity.class);
intent.setAction(Intent.ACTION_VIEW);
JSONObject options = args.getJSONObject(0);
intent.putExtra("src", options.getString("src"));
intent.putExtra("displayMode", 0);
intent.putExtra("inputFormat", 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
return "Ok!";
}
private String pause(Context context, JSONArray args) throws JSONException {
(new VideoActivity()).onPause();
return "true";
}
}