从MX Player获取活动结果

时间:2015-02-04 13:11:17

标签: java android

我正在解析一个直播流uri到mx播放器,我想得到结果,看看流媒体uri是否正常工作。 (当uri不起作用时,mx播放器发出错误无法播放视频)。这是我的代码。我已阅读MX Player API文档,但无法抓住如何分析onactivityresults。

Uri localUri = Uri.parse(link);
            Intent localIntent = new Intent("android.intent.action.VIEW");
            localIntent.setData(localUri);
            localIntent.putExtra("decode_mode", (byte) 0);
            localIntent.putExtra("fast_mode", true);
            localIntent.putExtra("secure_uri", true);
            localIntent.putExtra("title", name);
            localIntent.putExtra("position", 10000);
            localIntent.putExtra("return_result", true);
            try {
                localIntent.setPackage("com.mxtech.videoplayer.pro");
                startActivityForResult(localIntent, 0);
            } catch (ActivityNotFoundException localActivityNotFoundException1) {
                try {
                    localIntent.setPackage("com.mxtech.videoplayer.ad");
                    startActivityForResult(localIntent, 0);
                } catch (ActivityNotFoundException localActivityNotFoundException2) {
//Toast MX player is not installed
                }
@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == 0) {
            Toast.makeText(ChannelList.this, "Results Returned",
                    Toast.LENGTH_LONG).show();
        }
    }

1 个答案:

答案 0 :(得分:0)

首先,我在开始时也遇到了同样的问题。我总是在onActivityResult中找回data = null。

然后我在这里找到了一个很好的例子:https://groups.google.com/forum/#!topic/tasker/GvbDy9jMGzI

在官方网页https://sites.google.com/site/mxvpen/api

上阅读结果描述也是一个好主意。

我的代码在Android 4.4.4上使用MXPlayer 1.8.15正常工作。

主叫部分:

Intent intent = new Intent(Intent.ACTION_VIEW); 
intent.setPackage("com.mxtech.videoplayer.ad");
intent.setClassName("com.mxtech.videoplayer.ad", "com.mxtech.videoplayer.ad.ActivityScreen");
Uri videoUri = Uri.parse(cur_material.video_url);
intent.setDataAndType(videoUri, "application/x-mpegURL");
intent.setPackage("com.mxtech.videoplayer.ad"); // com.mxtech.videoplayer.pro
intent.putExtra("return_result", true);
//startActivity(intent);
startActivityForResult(intent, 0);

接收部分:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK)  // -1 RESULT_OK : Playback was completed or stopped by user request.
    //Activity.RESULT_CANCELED: User canceled before starting any playback. 
    //RESULT_ERROR (=Activity.RESULT_FIRST_USER): Last playback was ended with an error.

    if (data.getAction().equals("com.mxtech.intent.result.VIEW")) {
        //data.getData()
        int pos = data.getIntExtra("position", -1); // Last playback position in milliseconds. This extra will not exist if playback is completed.
        int dur = data.getIntExtra("duration", -1); // Duration of last played video in milliseconds. This extra will not exist if playback is completed.
        String cause = data.getStringExtra("end_by"); //  Indicates reason of activity closure.