From bc5c3f5f060b93f0314dc4f03c7e69ba24a22369 Mon Sep 17 00:00:00 2001 From: "David A. Velasco" Date: Thu, 14 Mar 2013 16:55:57 +0100 Subject: [PATCH] Added full screen video when embedded video is touched --- .../android/ui/preview/PreviewMediaFragment.java | 56 ++++++++++------------ .../PreviewVideoActivity.java | 40 +++++++++++++--- 2 files changed, 57 insertions(+), 39 deletions(-) rename src/com/owncloud/android/ui/{activity => preview}/PreviewVideoActivity.java (82%) diff --git a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java index fa173bd5..6dd58eab 100644 --- a/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java +++ b/src/com/owncloud/android/ui/preview/PreviewMediaFragment.java @@ -167,8 +167,8 @@ public class PreviewMediaFragment extends SherlockFragment implements mView = inflater.inflate(R.layout.file_preview, container, false); mImagePreview = (ImageView)mView.findViewById(R.id.image_preview); - mImagePreview.setOnTouchListener(this); mVideoPreview = (VideoView)mView.findViewById(R.id.video_preview); + mVideoPreview.setOnTouchListener(this); mMediaController = (MediaControlView)mView.findViewById(R.id.media_controller); @@ -368,7 +368,8 @@ public class PreviewMediaFragment extends SherlockFragment implements */ @Override public void onCompletion(MediaPlayer mp) { - // nothing, right now + mVideoPreview.seekTo(0); + mMediaController.updatePausePlay(); } @@ -404,18 +405,6 @@ public class PreviewMediaFragment extends SherlockFragment implements @Override - public void onResume() { - super.onResume(); - } - - - @Override - public void onPause() { - super.onPause(); - } - - - @Override public void onStop() { super.onStop(); if (mMediaServiceConnection != null) { @@ -437,31 +426,34 @@ public class PreviewMediaFragment extends SherlockFragment implements @Override public boolean onTouch(View v, MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_DOWN) { - if (v == mImagePreview && - mMediaServiceBinder != null && mFile.isAudio() && mMediaServiceBinder.isPlaying(mFile)) { - toggleMediaController(MediaService.MEDIA_CONTROL_PERMANENT); - return true; - - } else if (v == mVideoPreview) { - toggleMediaController(MediaService.MEDIA_CONTROL_SHORT_LIFE); - return true; - } + if (event.getAction() == MotionEvent.ACTION_DOWN && v == mVideoPreview) { + startFullScreenVideo(); + return true; } return false; } - private void toggleMediaController(int time) { - /* - if (mMediaController.isShowing()) { - mMediaController.hide(); - } else { - mMediaController.show(time); - } - */ + private void startFullScreenVideo() { + Intent i = new Intent(getActivity(), PreviewVideoActivity.class); + i.putExtra(PreviewVideoActivity.EXTRA_ACCOUNT, mAccount); + i.putExtra(PreviewVideoActivity.EXTRA_FILE, mFile); + i.putExtra(PreviewVideoActivity.EXTRA_AUTOPLAY, mVideoPreview.isPlaying()); + mVideoPreview.pause(); + i.putExtra(PreviewVideoActivity.EXTRA_START_POSITION, mVideoPreview.getCurrentPosition()); + startActivityForResult(i, 0); } + + @Override + public void onActivityResult (int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (resultCode == Activity.RESULT_OK) { + mSavedPlaybackPosition = data.getExtras().getInt(PreviewVideoActivity.EXTRA_START_POSITION); + mAutoplay = data.getExtras().getBoolean(PreviewVideoActivity.EXTRA_AUTOPLAY); + } + } + private void playAudio() { if (!mMediaServiceBinder.isPlaying(mFile)) { diff --git a/src/com/owncloud/android/ui/activity/PreviewVideoActivity.java b/src/com/owncloud/android/ui/preview/PreviewVideoActivity.java similarity index 82% rename from src/com/owncloud/android/ui/activity/PreviewVideoActivity.java rename to src/com/owncloud/android/ui/preview/PreviewVideoActivity.java index a3c30f6a..0b12920b 100644 --- a/src/com/owncloud/android/ui/activity/PreviewVideoActivity.java +++ b/src/com/owncloud/android/ui/preview/PreviewVideoActivity.java @@ -16,7 +16,7 @@ * */ -package com.owncloud.android.ui.activity; +package com.owncloud.android.ui.preview; import android.accounts.Account; import android.app.Activity; @@ -53,13 +53,22 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen /** Key to receive an {@link OCFile} to play as an extra value in an {@link Intent} */ public static final String EXTRA_FILE = "FILE"; + /** Key to receive the ownCloud {@link Account} where the file to play is saved as an extra value in an {@link Intent} */ public static final String EXTRA_ACCOUNT = "ACCOUNT"; - private static final String TAG = null; + /** Key to receive a flag signaling if the video should be started immediately */ + public static final String EXTRA_AUTOPLAY = "AUTOPLAY"; + + /** Key to receive the position of the playback where the video should be put at start */ + public static final String EXTRA_START_POSITION = "START_POSITION"; + + private static final String TAG = PreviewVideoActivity.class.getSimpleName(); private OCFile mFile; // video file to play private Account mAccount; // ownCloud account holding mFile + private int mSavedPlaybackPosition; // in the unit time handled by MediaPlayer.getCurrentPosition() + private boolean mAutoplay; // when 'true', the playback starts immediately with the activity private VideoView mVideoPlayer; // view to play the file; both performs and show the playback private MediaController mMediaController; // panel control used by the user to control the playback @@ -79,8 +88,11 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen setContentView(R.layout.video_layout); - mFile = getIntent().getExtras().getParcelable(EXTRA_FILE); - mAccount = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT); + Bundle extras = getIntent().getExtras(); + mFile = extras.getParcelable(EXTRA_FILE); + mAccount = extras.getParcelable(EXTRA_ACCOUNT); + mSavedPlaybackPosition = extras.getInt(EXTRA_START_POSITION); + mAutoplay = extras.getBoolean(EXTRA_AUTOPLAY); mVideoPlayer = (VideoView) findViewById(R.id.videoPlayer); @@ -97,6 +109,7 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen mVideoPlayer.setVideoPath(mFile.getStoragePath()); } else if (mAccount != null) { + // not working now String url = AccountUtils.constructFullURLForAccount(this, mAccount) + mFile.getRemotePath(); mVideoPlayer.setVideoURI(Uri.parse(url)); @@ -116,6 +129,16 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen } + @Override + public void onBackPressed() { + Intent i = new Intent(); + i.putExtra(EXTRA_AUTOPLAY, mVideoPlayer.isPlaying()); + i.putExtra(EXTRA_START_POSITION, mVideoPlayer.getCurrentPosition()); + setResult(RESULT_OK, i); + super.onBackPressed(); + } + + /** * Called when the file is ready to be played. * @@ -125,7 +148,10 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen */ @Override public void onPrepared(MediaPlayer vp) { - mVideoPlayer.start(); + mVideoPlayer.seekTo(mSavedPlaybackPosition); + if (mAutoplay) { + mVideoPlayer.start(); + } mMediaController.show(5000); } @@ -133,13 +159,13 @@ public class PreviewVideoActivity extends Activity implements OnCompletionListen /** * Called when the file is finished playing. * - * Finishes the activity. + * Rewinds the video * * @param mp {@link MediaPlayer} instance performing the playback. */ @Override public void onCompletion(MediaPlayer mp) { - this.finish(); + mVideoPlayer.seekTo(0); } -- 2.11.0