在我的视频插件结束播放视频后,我需要将控件返回给 WebView。
VideoView 在 UIThread 中播放视频。视频完成后,线程应该结束,主 WebView 应该设置为焦点和活动。
我怎样才能做到这一点?
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() {
final VideoView videoHolder = new VideoView(cordova.getActivity().getApplicationContext());
cordova.getActivity().setContentView(videoHolder);
videoHolder.setVideoURI(Uri.parse("file:///sdcard/Android/data/Bis/v2.mp4"));
videoHolder.requestFocus();
videoHolder.start();
callbackContext.success(); // Thread-safe.
videoHolder.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
// return Control back to the WebView
}
});
}
});
return true;
}
return false;
}