PhoneGap:对于新的Runnable类型,未定义setContentView

时间:2013-01-16 14:15:47

标签: android cordova phonegap-plugins

我正在尝试使用VideoView创建一个PhoneGap插件播放视频。但我收到以下错误:

对于new Runnable类型,

setContentView未定义。

package com.phonegap.plugins.video;

import org.json.JSONArray;
import org.json.JSONException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;
import android.widget.VideoView;

public class VideoPlayer extends CordovaPlugin {

@Override
public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
    if ("playVideo".equals(action)) {
        cordova.getActivity().runOnUiThread(new Runnable() {
            public void run() {
                VideoView videoHolder = new VideoView(cordova.getActivity().getApplicationContext());
                setContentView(videoHolder);
                videoHolder.setVideoURI(Uri.parse("file:///sdcard/Android/data/Bis/v2.mp4"));
                videoHolder.requestFocus();
                videoHolder.start();            
                callbackContext.success(); // Thread-safe.
            }
        });
        return true;
    }
    return false;
}

SetContentView需要调用的方式有什么变化吗?

1 个答案:

答案 0 :(得分:2)

cordova.getActivity().setContentView()。因为在Runnable内部,这指的是内部类Runnable