summaryrefslogtreecommitdiffstats
path: root/src/com/android/camera/MovieView.java
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:54 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2008-12-17 18:05:54 -0800
commit0eaec58e292ce4eaa6baadecf643f0f65e48d278 (patch)
tree78ef71512fa619ca4befa57b239be433f6aae74e /src/com/android/camera/MovieView.java
parent1d4c75065966c4f6f56900e31f655bfd1b334435 (diff)
downloadLegacyCamera-0eaec58e292ce4eaa6baadecf643f0f65e48d278.zip
LegacyCamera-0eaec58e292ce4eaa6baadecf643f0f65e48d278.tar.gz
LegacyCamera-0eaec58e292ce4eaa6baadecf643f0f65e48d278.tar.bz2
Code drop from //branches/cupcake/...@124589
Diffstat (limited to 'src/com/android/camera/MovieView.java')
-rw-r--r--src/com/android/camera/MovieView.java124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/com/android/camera/MovieView.java b/src/com/android/camera/MovieView.java
new file mode 100644
index 0000000..58e80df
--- /dev/null
+++ b/src/com/android/camera/MovieView.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2007 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.camera;
+
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+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.view.View;
+import android.widget.MediaController;
+import android.widget.VideoView;
+
+public class MovieView extends Activity implements MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener
+{
+ private static final String TAG = "MovieView";
+ // Copied from MediaPlaybackService in the Music Player app. Should be public, but isn't.
+ private static final String SERVICECMD = "com.android.music.musicservicecommand";
+ private static final String CMDNAME = "command";
+ private static final String CMDPAUSE = "pause";
+
+ private VideoView mVideoView;
+ private View mProgressView;
+ private boolean mFinishOnCompletion;
+ public MovieView()
+ {
+ }
+
+ @Override
+ public void onCreate(Bundle icicle)
+ {
+ super.onCreate(icicle);
+
+ setContentView(R.layout.movie_view);
+
+ mVideoView = (VideoView) findViewById(R.id.surface_view);
+ mProgressView = findViewById(R.id.progress_indicator);
+ Intent intent = getIntent();
+ if (intent.hasExtra(MediaStore.EXTRA_SCREEN_ORIENTATION)) {
+ int orientation = intent.getIntExtra(MediaStore.EXTRA_SCREEN_ORIENTATION,
+ ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
+ if (orientation != getRequestedOrientation()) {
+ setRequestedOrientation(orientation);
+ }
+ }
+ mFinishOnCompletion = intent.getBooleanExtra(MediaStore.EXTRA_FINISH_ON_COMPLETION, true);
+ Uri uri = intent.getData();
+
+ // For streams that we expect to be slow to start up, show a
+ // progress spinner until playback starts.
+ String scheme = uri.getScheme();
+ if ("http".equalsIgnoreCase(scheme) ||
+ "rtsp".equalsIgnoreCase(scheme)) {
+ mHandler.postDelayed(mPlayingChecker, 250);
+ } else {
+ mProgressView.setVisibility(View.GONE);
+ }
+
+ mVideoView.setOnErrorListener(this);
+ mVideoView.setOnCompletionListener(this);
+ mVideoView.setVideoURI(uri);
+ 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);
+
+ mVideoView.start();
+ }
+
+ @Override
+ public void onPause() {
+ mHandler.removeCallbacksAndMessages(null);
+ super.onPause();
+ }
+
+ Handler mHandler = new Handler() {
+ @Override
+ public void handleMessage(Message msg) {
+ }
+ };
+
+ Runnable mPlayingChecker = new Runnable() {
+ public void run() {
+ if (mVideoView.isPlaying()) {
+ mProgressView.setVisibility(View.GONE);
+ } else {
+ mHandler.postDelayed(mPlayingChecker, 250);
+ }
+ }
+ };
+
+ public boolean onError(MediaPlayer player, int arg1, int arg2) {
+ mHandler.removeCallbacksAndMessages(null);
+ mProgressView.setVisibility(View.GONE);
+ return false;
+ }
+
+ public void onCompletion(MediaPlayer mp) {
+ if (mFinishOnCompletion) {
+ finish();
+ }
+ }
+}