2013-01-16 26 views
0

我試圖創建PhoneGap插件tp使用VideoView播放視頻。但是我收到以下錯誤:PhoneGap:setContentView未定義爲新的類型Runnable

setContentView未定義爲新的Runnable類型。

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需要調用的方式是否有任何改變?

回答

2

cordova.getActivity().setContentView()。由於在Runnable之內,這指的是內部類Runnable

+0

對於類型VideoPlayer未定義方法setContentView() –

+0

試試這種方法。對不起 – Blackbelt

+0

非常感謝大家..被困在這個小時。真的很感激它。謝謝!!! –