1

我正在尝试创建一个 PhoneGap 插件,它使用 Android VideoView 在没有视频控件的情况下播放全屏视频。但这似乎不起作用。调用插件函数没有做任何事情。难道我做错了什么?或者这甚至可能吗?

package com.phonegap.plugins.video;

import org.json.JSONArray;
import org.json.JSONException;

import android.net.Uri;

import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;

import android.widget.VideoView;

public class VideoPlayer extends Plugin {

    @Override
    public PluginResult execute(String action, JSONArray args, String callbackId) {

        final Plugin that = this;
        final String id = callbackId;

        super.cordova.getActivity().runOnUiThread(new Runnable() {
            //@Override
            public void run() {
                    VideoView videoHolder = new VideoView(cordova.getActivity().getApplicationContext());
                    //setContentView(videoHolder);
                    videoHolder.setVideoURI(Uri.parse("file:///sdcard/Android/data/MyApp/v2.mp4"));
                    videoHolder.requestFocus();
                    videoHolder.start();
                    that.success(new PluginResult(PluginResult.Status.OK), id);
            }
        });

        PluginResult result = new PluginResult(PluginResult.Status.NO_RESULT);
        result.setKeepCallback(true);
        return result;
    }
}

我的 JavaScript 看起来像这样:

function VideoPlayer() {
};


VideoPlayer.prototype.play = function(url) {
    cordova.exec(null, null, "VideoPlayer", "playVideo", [url]);
};


if(!window.plugins) {
    window.plugins = {};
}
if (!window.plugins.videoPlayer) {
    window.plugins.videoPlayer = new VideoPlayer();
}

我正在调用如下函数:

<a href='#' onclick='javascript:window.plugins.videoPlayer.play("file:///sdcard/Android/data/MyApp/v2.mp4");'>Bismillah</a>
4

1 回答 1

1

检查这个插件https://github.com/macdonst/VideoPlayer 它对我有用,也很容易配置集成到项目中

于 2014-02-22T07:50:36.753 回答