VLC intent always returns result code 0 - RESULT_C

2019-09-20 10:22发布

This code works fine and starts video playback as expected, but when backing out of VLC in our Cordova app, the correct requestCode (42) is returned, but resultCode is always 0 (RESULT_CANCELLED) and returned Intent is null. The same thing occurs if the video finishes playing and VLC exits on its own. According to the documentation, we should be getting RESULT_OK with a return Intent containing information such as extra_position (to get the video position upon exit).

Other Intents work fine, such as pick contact intent.

Tested on Android TV emulator, Nvidia Shield Tablet and an Android phone (Note 4). Tried VLC 2.0.6, latest Betas and nightly builds.

   public void start(String uri, long position) {
    int vlcRequestCode = 42;
    Uri parsedUri = Uri.parse(uri);
    Intent vlcIntent = new Intent(Intent.ACTION_VIEW);
    vlcIntent.setPackage("org.videolan.vlc");
    vlcIntent.setDataAndTypeAndNormalize(parsedUri, "video/*");
    vlcIntent.putExtra("position", position);

    this.cordova.startActivityForResult(this, vlcIntent, vlcRequestCode);
}

public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    JSONObject json = new JSONObject();

    json.put("requestCode", requestCode);
    json.put("resultCode", resultCode);
    json.put("intentIsNull", intent == null);

    this.callbackContext.success(json.toString());
}    

1条回答
Evening l夕情丶
2楼-- · 2019-09-20 10:48

Replace

vlcIntent.setPackage("org.videolan.vlc");

with

vlcIntent.setComponent(new ComponentName("org.videolan.vlc", "org.videolan.vlc.gui.video.VideoPlayerActivity"));

This should give the result you are looking for.

查看更多
登录 后发表回答