7 package com.google.appinventor.components.runtime.util;
15 import android.app.Dialog;
16 import android.media.MediaPlayer;
17 import android.media.MediaPlayer.OnCompletionListener;
18 import android.media.MediaPlayer.OnPreparedListener;
19 import android.os.Bundle;
20 import android.os.Handler;
21 import android.util.Log;
22 import android.view.Gravity;
23 import android.view.MotionEvent;
24 import android.view.View;
25 import android.view.View.OnTouchListener;
26 import android.view.ViewGroup;
27 import android.view.ViewGroup.LayoutParams;
28 import android.widget.FrameLayout;
29 import android.widget.VideoView;
31 import java.io.IOException;
74 private Dialog mFullScreenVideoDialog;
75 private FrameLayout mFullScreenVideoHolder;
76 private VideoView mFullScreenVideoView;
78 private FrameLayout.LayoutParams mMediaControllerParams =
new FrameLayout.LayoutParams(
79 LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, Gravity.BOTTOM);
88 private Bundle mFullScreenVideoBundle;
91 private Handler mHandler;
106 mFullScreenVideoDialog =
new Dialog(mForm,
107 R.style.Theme_NoTitleBar_Fullscreen) {
108 public void onBackPressed() {
110 Bundle values =
new Bundle();
112 mFullScreenVideoView.getCurrentPosition());
114 mFullScreenVideoView.isPlaying());
118 super.onBackPressed();
121 public void onStart() {
166 Log.i(
"Form.fullScreenVideoAction",
"Actions:" + action +
" Source:"
167 + source +
": Current Source:" + mFullScreenPlayer +
" Data:" + data);
168 Bundle result =
new Bundle();
170 if (source == mFullScreenPlayer) {
173 return doFullScreenVideoAction(source, (Bundle) data);
176 mFullScreenVideoView.pause();
183 mFullScreenVideoView.start();
190 mFullScreenVideoView.seekTo((Integer) data);
197 mFullScreenVideoView.stopPlayback();
211 result.putInt(
ACTION_DATA, mFullScreenVideoView.getDuration());
219 if (
showing() && mFullScreenPlayer !=
null) {
220 Bundle values =
new Bundle();
222 mFullScreenVideoView.getCurrentPosition());
224 mFullScreenVideoView.isPlaying());
226 mFullScreenVideoBundle
230 return doFullScreenVideoAction(source, (Bundle) data);
241 private Bundle doFullScreenVideoAction(
VideoPlayer source, Bundle data) {
242 Log.i(
"Form.doFullScreenVideoAction",
"Source:" + source +
" Data:" + data);
243 Bundle result =
new Bundle();
246 mFullScreenPlayer = source;
247 mFullScreenVideoBundle = data;
248 if (!mFullScreenVideoDialog.isShowing()) {
252 mFullScreenVideoView.pause();
260 mFullScreenVideoView.isPlaying());
262 mFullScreenVideoView.getCurrentPosition());
264 mFullScreenVideoBundle
267 mFullScreenPlayer =
null;
268 mFullScreenVideoBundle =
null;
285 if (mFullScreenVideoBundle ==
null)
286 Log.i(
"Form.createFullScreenVideoDialog",
"mFullScreenVideoBundle is null");
288 mFullScreenVideoView =
new VideoView(mForm);
289 mFullScreenVideoHolder =
new FrameLayout(mForm);
292 mFullScreenVideoView.setId(mFullScreenVideoView.hashCode());
293 mFullScreenVideoHolder.setId(mFullScreenVideoHolder.hashCode());
295 mFullScreenVideoView.setMediaController(mFullScreenVideoController);
297 mFullScreenVideoView.setOnTouchListener(
new OnTouchListener() {
300 public boolean onTouch(View arg0, MotionEvent arg1) {
301 Log.i(
"FullScreenVideoUtil..onTouch",
"Video Touched!!");
305 mFullScreenVideoController.
setAnchorView(mFullScreenVideoView);
308 if (orientation.equals(
"landscape")
309 || orientation.equals(
"sensorLandscape")
310 || orientation.equals(
"reverseLandscape")) {
311 mFullScreenVideoView.setLayoutParams(
new FrameLayout.LayoutParams(
312 FrameLayout.LayoutParams.WRAP_CONTENT,
313 FrameLayout.LayoutParams.FILL_PARENT, Gravity.CENTER));
315 mFullScreenVideoView.setLayoutParams(
new FrameLayout.LayoutParams(
316 FrameLayout.LayoutParams.FILL_PARENT,
317 FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER));
319 mFullScreenVideoHolder
320 .setLayoutParams(
new ViewGroup.LayoutParams(
321 ViewGroup.LayoutParams.FILL_PARENT,
322 ViewGroup.LayoutParams.FILL_PARENT));
324 mFullScreenVideoHolder.addView(mFullScreenVideoView);
327 mFullScreenVideoController.
addTo(mFullScreenVideoHolder,
328 mMediaControllerParams);
330 mFullScreenVideoDialog.setContentView(mFullScreenVideoHolder);
331 return mFullScreenVideoDialog;
342 mFullScreenVideoView.setOnPreparedListener(
this);
343 mFullScreenVideoView.setOnCompletionListener(
this);
350 return mFullScreenVideoDialog !=
null;
377 public boolean setSource(String source,
boolean clearSeek) {
391 }
catch (IOException e) {
403 if (mFullScreenPlayer !=
null) {
414 "FullScreenVideoUtil..onPrepared",
416 + mFullScreenVideoBundle
418 mFullScreenVideoView.seekTo(mFullScreenVideoBundle
420 if (mFullScreenVideoBundle
422 mFullScreenVideoView.start();
424 mFullScreenVideoView.start();
425 mHandler.postDelayed(
new Runnable() {
429 mFullScreenVideoView.pause();
441 mFullScreenVideoBundle
445 }
catch (IOException e) {