diff options
Diffstat (limited to 'src/com/android/camera/MovieView.java')
-rw-r--r-- | src/com/android/camera/MovieView.java | 97 |
1 files changed, 93 insertions, 4 deletions
diff --git a/src/com/android/camera/MovieView.java b/src/com/android/camera/MovieView.java index 58e80df..b93336c 100644 --- a/src/com/android/camera/MovieView.java +++ b/src/com/android/camera/MovieView.java @@ -18,14 +18,22 @@ package com.android.camera; import android.app.Activity; +import android.app.AlertDialog; +import android.content.ContentValues; +import android.content.DialogInterface; import android.content.Intent; +import android.content.DialogInterface.OnCancelListener; +import android.content.DialogInterface.OnClickListener; import android.content.pm.ActivityInfo; +import android.database.Cursor; +import android.database.sqlite.SQLiteException; import android.media.MediaPlayer; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.provider.MediaStore; +import android.provider.MediaStore.Video; import android.view.View; import android.widget.MediaController; import android.widget.VideoView; @@ -41,6 +49,7 @@ public class MovieView extends Activity implements MediaPlayer.OnErrorListener, private VideoView mVideoView; private View mProgressView; private boolean mFinishOnCompletion; + private Uri mUri; public MovieView() { } @@ -63,11 +72,11 @@ public class MovieView extends Activity implements MediaPlayer.OnErrorListener, } } mFinishOnCompletion = intent.getBooleanExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, true); - Uri uri = intent.getData(); + mUri = intent.getData(); // For streams that we expect to be slow to start up, show a // progress spinner until playback starts. - String scheme = uri.getScheme(); + String scheme = mUri.getScheme(); if ("http".equalsIgnoreCase(scheme) || "rtsp".equalsIgnoreCase(scheme)) { mHandler.postDelayed(mPlayingChecker, 250); @@ -77,20 +86,100 @@ public class MovieView extends Activity implements MediaPlayer.OnErrorListener, mVideoView.setOnErrorListener(this); mVideoView.setOnCompletionListener(this); - mVideoView.setVideoURI(uri); + mVideoView.setVideoURI(mUri); mVideoView.setMediaController(new MediaController(this)); mVideoView.requestFocus(); // make the video view handle keys for seeking and pausing Intent i = new Intent(SERVICECMD); i.putExtra(CMDNAME, CMDPAUSE); sendBroadcast(i); + { + final Integer bookmark = getBookmark(); + if (bookmark != null) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.resume_playing_title); + builder.setMessage(String.format( + getString(R.string.resume_playing_message), + MenuHelper.formatDuration(this, bookmark))); + builder.setOnCancelListener(new OnCancelListener() { + public void onCancel(DialogInterface dialog) { + finish(); + }}); + builder.setPositiveButton(R.string.resume_playing_resume, + new OnClickListener(){ + public void onClick(DialogInterface dialog, int which) { + mVideoView.seekTo(bookmark); + mVideoView.start(); + }}); + builder.setNegativeButton(R.string.resume_playing_restart, new OnClickListener(){ + public void onClick(DialogInterface dialog, int which) { + mVideoView.start(); + }}); + builder.show(); + } else { + mVideoView.start(); + } + } + } - mVideoView.start(); + private Integer getBookmark() { + String scheme = mUri.getScheme(); + if ("content".equalsIgnoreCase(scheme)) { + String[] projection = new String[]{Video.VideoColumns.DURATION, + Video.VideoColumns.BOOKMARK}; + try { + Cursor cursor = getContentResolver().query(mUri, projection, null, null, null); + if (cursor != null) { + try { + if ( cursor.moveToFirst() ) { + int duration = getCursorInteger(cursor, 0); + int bookmark = getCursorInteger(cursor, 1); + final int ONE_MINUTE = 60 * 1000; + final int TWO_MINUTES = 2 * ONE_MINUTE; + final int FIVE_MINUTES = 5 * ONE_MINUTE; + if ((bookmark < TWO_MINUTES) + || (duration < FIVE_MINUTES) + || (bookmark > (duration - ONE_MINUTE))) { + return null; + } + + return new Integer(bookmark); + } + } finally { + cursor.close(); + } + } + } catch (SQLiteException e) { + // ignore + } + } + return null; + } + + private int getCursorInteger(Cursor cursor, int index) { + try { + return cursor.getInt(index); + } catch (SQLiteException e) { + return 0; + } catch (NumberFormatException e) { + return 0; + } + + } + + private void setBookmark(int bookmark) { + String scheme = mUri.getScheme(); + if ("content".equalsIgnoreCase(scheme)) { + ContentValues values = new ContentValues(); + values.put(Video.VideoColumns.BOOKMARK, Integer.toString(bookmark)); + getContentResolver().update(mUri, values, null, null); + } } @Override public void onPause() { mHandler.removeCallbacksAndMessages(null); + setBookmark(mVideoView.getCurrentPosition()); super.onPause(); } |