2013-01-14 68 views
1

我正在嘗試創建一個PhoneGap插件,它使用Android VideoView在沒有視頻控件的情況下播放全屏視頻。但它似乎並不奏效。調用插件函數沒有做任何事情。難道我做錯了什麼?或者這甚至可能嗎?Android VideoView可以用作PhoneGap插件嗎?

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> 
+0

我想幫助這個插件。你有github或者atlassian或者bitbucket項目嗎? Best,SisaCodes – bigTimer314

+0

你是否設法解決這個問題?我有同樣的要求,請告訴你如何做到這一點? –

+0

我也很想知道你是否最終管理了這個。 – jwktje

回答