diff options
Diffstat (limited to 'src/com/android/gallery3d')
-rw-r--r-- | src/com/android/gallery3d/app/MovieActivity.java | 52 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/MoviePlayer.java | 112 |
2 files changed, 149 insertions, 15 deletions
diff --git a/src/com/android/gallery3d/app/MovieActivity.java b/src/com/android/gallery3d/app/MovieActivity.java index 30b12243f..5152e5b39 100644 --- a/src/com/android/gallery3d/app/MovieActivity.java +++ b/src/com/android/gallery3d/app/MovieActivity.java @@ -62,6 +62,10 @@ import com.android.gallery3d.R; import com.android.gallery3d.common.ApiHelper; import com.android.gallery3d.common.Utils; import com.android.gallery3d.ui.Knob; +import org.codeaurora.gallery3d.ext.IActivityHooker; +import org.codeaurora.gallery3d.ext.MovieItem; +import org.codeaurora.gallery3d.ext.IMovieItem; +import org.codeaurora.gallery3d.video.ExtensionHelper; /** * This activity plays a video from a specified URI. @@ -79,7 +83,6 @@ public class MovieActivity extends Activity { private MoviePlayer mPlayer; private boolean mFinishOnCompletion; private Uri mUri; - private boolean mTreatUpAsBack; private static final short BASSBOOST_MAX_STRENGTH = 1000; private static final short VIRTUALIZER_MAX_STRENGTH = 1000; @@ -100,6 +103,9 @@ public class MovieActivity extends Activity { private Knob mBassBoostKnob; private Knob mVirtualizerKnob; + private IMovieItem mMovieItem; + private IActivityHooker mMovieHooker; + private final BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(final Context context, final Intent intent) { @@ -153,11 +159,14 @@ public class MovieActivity extends Activity { setSystemUiVisibility(rootView); Intent intent = getIntent(); + + mMovieHooker = ExtensionHelper.getHooker(this); + initMovieInfo(intent); + initializeActionBar(intent); mFinishOnCompletion = intent.getBooleanExtra( MediaStore.EXTRA_FINISH_ON_COMPLETION, true); - mTreatUpAsBack = intent.getBooleanExtra(KEY_TREAT_UP_AS_BACK, false); - mPlayer = new MoviePlayer(rootView, this, intent.getData(), savedInstanceState, + mPlayer = new MoviePlayer(rootView, this, mMovieItem, savedInstanceState, !mFinishOnCompletion) { @Override public void onCompletion() { @@ -183,7 +192,10 @@ public class MovieActivity extends Activity { // We set the background in the theme to have the launching animation. // But for the performance (and battery), we remove the background here. win.setBackgroundDrawable(null); - + mMovieHooker.init(this, intent); + mMovieHooker.setParameter(null, mPlayer.getMoviePlayerExt()); + mMovieHooker.setParameter(null, mMovieItem); + mMovieHooker.setParameter(null, mPlayer.getVideoSurface()); // Determine available/supported effects final Descriptor[] effects = AudioEffect.queryEffects(); for (final Descriptor effect : effects) { @@ -299,6 +311,14 @@ public class MovieActivity extends Activity { return true; } }); + mMovieHooker.onCreateOptionsMenu(menu); + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + mMovieHooker.onPrepareOptionsMenu(menu); return true; } @@ -402,19 +422,16 @@ public class MovieActivity extends Activity { public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); if (id == android.R.id.home) { - if (mTreatUpAsBack) { - finish(); - } else { - startActivity(new Intent(this, GalleryActivity.class)); - finish(); - } + // If click back up button, we will always finish current activity and + // back to previous one. + finish(); return true; } else if (id == R.id.action_share) { startActivity(Intent.createChooser(createShareIntent(), getString(R.string.share))); return true; } - return false; + return mMovieHooker.onOptionsItemSelected(item); } public void showHeadsetPlugToast() { @@ -494,4 +511,17 @@ public class MovieActivity extends Activity { return mPlayer.onKeyUp(keyCode, event) || super.onKeyUp(keyCode, event); } + + private boolean isSharable() { + String scheme = mUri.getScheme(); + return ContentResolver.SCHEME_FILE.equals(scheme) + || (ContentResolver.SCHEME_CONTENT.equals(scheme) && MediaStore.AUTHORITY + .equals(mUri.getAuthority())); + } + private void initMovieInfo(Intent intent) { + Uri original = intent.getData(); + String mimeType = intent.getType(); + mMovieItem = new MovieItem(original, mimeType, null); + mMovieItem.setOriginalUri(original); + } } diff --git a/src/com/android/gallery3d/app/MoviePlayer.java b/src/com/android/gallery3d/app/MoviePlayer.java index 962afeafb..09fd272ae 100644 --- a/src/com/android/gallery3d/app/MoviePlayer.java +++ b/src/com/android/gallery3d/app/MoviePlayer.java @@ -35,6 +35,7 @@ import android.os.Bundle; import android.os.Handler; import android.view.KeyEvent; import android.view.MotionEvent; +import android.view.SurfaceView; import android.view.View; import android.view.ViewGroup; import android.widget.VideoView; @@ -44,6 +45,9 @@ import com.android.gallery3d.common.ApiHelper; import com.android.gallery3d.common.BlobCache; import com.android.gallery3d.util.CacheManager; import com.android.gallery3d.util.GalleryUtils; +import org.codeaurora.gallery3d.ext.IMoviePlayer; +import org.codeaurora.gallery3d.ext.IMovieItem; +import org.codeaurora.gallery3d.video.ExtensionHelper; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -75,6 +79,9 @@ public class MoviePlayer implements // Otherwise, we pause the player. private static final long RESUMEABLE_TIMEOUT = 3 * 60 * 1000; // 3 mins + public static final int STREAMING_LOCAL = 0; + private int mStreamingType = STREAMING_LOCAL; + private Context mContext; private final VideoView mVideoView; private final View mRootView; @@ -97,6 +104,24 @@ public class MoviePlayer implements private Virtualizer mVirtualizer; + private MoviePlayerExtension mPlayerExt = new MoviePlayerExtension(); + private boolean mCanReplay; + private TState mTState = TState.PLAYING; + private IMovieItem mMovieItem; + + private enum TState { + PLAYING, + PAUSED, + STOPED, + COMPELTED, + RETRY_ERROR + } + + interface Restorable { + void onRestoreInstanceState(Bundle icicle); + void onSaveInstanceState(Bundle outState); + } + private final Runnable mPlayingChecker = new Runnable() { @Override public void run() { @@ -117,18 +142,20 @@ public class MoviePlayer implements }; public MoviePlayer(View rootView, final MovieActivity movieActivity, - Uri videoUri, Bundle savedInstance, boolean canReplay) { + IMovieItem info, Bundle savedInstance, boolean canReplay) { mContext = movieActivity.getApplicationContext(); mRootView = rootView; mVideoView = (VideoView) rootView.findViewById(R.id.surface_view); mBookmarker = new Bookmarker(movieActivity); - mUri = videoUri; mController = new MovieControllerOverlay(mContext); ((ViewGroup)rootView).addView(mController.getView()); mController.setListener(this); mController.setCanReplay(canReplay); + init(info, canReplay); + mUri = mMovieItem.getUri(); + mVideoView.setOnErrorListener(this); mVideoView.setOnCompletionListener(this); mVideoView.setVideoURI(mUri); @@ -191,6 +218,7 @@ public class MoviePlayer implements mResumeableTime = savedInstance.getLong(KEY_RESUMEABLE_TIME, Long.MAX_VALUE); mVideoView.start(); mVideoView.suspend(); + onRestoreInstanceState(savedInstance); mHasPaused = true; } else { final Integer bookmark = mBookmarker.getBookmark(mUri); @@ -242,6 +270,7 @@ public class MoviePlayer implements public void onSaveInstanceState(Bundle outState) { outState.putInt(KEY_VIDEO_POSITION, mVideoPosition); outState.putLong(KEY_RESUMEABLE_TIME, mResumeableTime); + onSaveInstanceStateMore(outState); } private void showResumeDialog(Context context, final int bookmark) { @@ -332,6 +361,11 @@ public class MoviePlayer implements } mVideoView.start(); + //we may start video from stopVideo, + //this case, we should reset canReplay flag according canReplay and loop + boolean loop = mPlayerExt.getLoop(); + boolean canReplay = loop ? loop : mCanReplay; + mController.setCanReplay(canReplay); setProgress(); } @@ -358,8 +392,15 @@ public class MoviePlayer implements @Override public void onCompletion(MediaPlayer mp) { - mController.showEnded(); - onCompletion(); + if (mPlayerExt.getLoop()) { + onReplay(); + } else { //original logic + mTState = TState.COMPELTED; + if (mCanReplay) { + mController.showEnded(); + } + onCompletion(); + } } public void onCompletion() { @@ -459,6 +500,11 @@ public class MoviePlayer implements || keyCode == KeyEvent.KEYCODE_MEDIA_PAUSE; } + private void init(IMovieItem info, boolean canReplay) { + mCanReplay = canReplay; + mMovieItem = info; + } + // We want to pause when the headset is unplugged. private class AudioBecomingNoisyReceiver extends BroadcastReceiver { @@ -484,6 +530,64 @@ public class MoviePlayer implements public void setOnPreparedListener(MediaPlayer.OnPreparedListener listener) { mVideoView.setOnPreparedListener(listener); } + + public boolean isLocalFile() { + if (mStreamingType == STREAMING_LOCAL) { + return true; + } + return false; + } + + public IMoviePlayer getMoviePlayerExt() { + return mPlayerExt; + } + + public SurfaceView getVideoSurface() { + return mVideoView; + } + + private void onSaveInstanceStateMore(Bundle outState) { + + mPlayerExt.onSaveInstanceState(outState); + } + + private void onRestoreInstanceState(Bundle icicle) { + + mPlayerExt.onRestoreInstanceState(icicle); + } + + private class MoviePlayerExtension implements IMoviePlayer, Restorable { + + private static final String KEY_VIDEO_IS_LOOP = "video_is_loop"; + + private boolean mIsLoop; + + @Override + public boolean getLoop() { + return mIsLoop; + } + + @Override + public void setLoop(boolean loop) { + if (isLocalFile()) { + mIsLoop = loop; + mController.setCanReplay(loop); + } + } + + @Override + public void onRestoreInstanceState(Bundle icicle) { + mIsLoop = icicle.getBoolean(KEY_VIDEO_IS_LOOP, false); + if (mIsLoop) { + mController.setCanReplay(true); + } // else will get can replay from intent. + } + + @Override + public void onSaveInstanceState(Bundle outState) { + outState.putBoolean(KEY_VIDEO_IS_LOOP, mIsLoop); + } + }; } class Bookmarker { |