summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-08-19 13:57:22 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2009-08-19 13:57:22 -0700
commitbda918ceb6c51212b1b511ba3b22843c1e9c01c5 (patch)
tree158a5ad6019bb47c8dae7fa8fe61677a414e5527
parent07782e079f4410090f87dca109e24e9436653654 (diff)
parentc818b141ee97a7a26fe069456d4b662d06c9eaea (diff)
downloadframeworks_base-bda918ceb6c51212b1b511ba3b22843c1e9c01c5.zip
frameworks_base-bda918ceb6c51212b1b511ba3b22843c1e9c01c5.tar.gz
frameworks_base-bda918ceb6c51212b1b511ba3b22843c1e9c01c5.tar.bz2
Merge change 21888 into eclair
* changes: Do not enable the rew/pause/ffwd buttons when the media being played does not support these functions. This extends the MediaPlayerControl interface with some new methods, and uses reflection to detect whether the old or new interface is used by an application.
-rw-r--r--api/current.xml66
-rw-r--r--core/java/android/widget/MediaController.java41
-rw-r--r--core/java/android/widget/VideoView.java30
3 files changed, 127 insertions, 10 deletions
diff --git a/api/current.xml b/api/current.xml
index e9082bc..ec76edb 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -175196,6 +175196,39 @@
deprecated="not deprecated"
visibility="public"
>
+<method name="canPause"
+ return="boolean"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="canSeekBackward"
+ return="boolean"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="canSeekForward"
+ return="boolean"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
<method name="getBufferPercentage"
return="int"
abstract="true"
@@ -183524,6 +183557,39 @@
<parameter name="defStyle" type="int">
</parameter>
</constructor>
+<method name="canPause"
+ return="boolean"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="canSeekBackward"
+ return="boolean"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
+<method name="canSeekForward"
+ return="boolean"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+</method>
<method name="getBufferPercentage"
return="int"
abstract="false"
diff --git a/core/java/android/widget/MediaController.java b/core/java/android/widget/MediaController.java
index 0c9d980..9910c37 100644
--- a/core/java/android/widget/MediaController.java
+++ b/core/java/android/widget/MediaController.java
@@ -250,6 +250,29 @@ public class MediaController extends FrameLayout {
}
/**
+ * Disable pause or seek buttons if the stream cannot be paused or seeked.
+ * This requires the control interface to be a MediaPlayerControlExt
+ */
+ private void disableUnsupportedButtons() {
+ try {
+ if (mPauseButton != null && !mPlayer.canPause()) {
+ mPauseButton.setEnabled(false);
+ }
+ if (mRewButton != null && !mPlayer.canSeekBackward()) {
+ mRewButton.setEnabled(false);
+ }
+ if (mFfwdButton != null && !mPlayer.canSeekForward()) {
+ mFfwdButton.setEnabled(false);
+ }
+ } catch (IncompatibleClassChangeError ex) {
+ // We were given an old version of the interface, that doesn't have
+ // the canPause/canSeekXYZ methods. This is OK, it just means we
+ // assume the media can be paused and seeked, and so we don't disable
+ // the buttons.
+ }
+ }
+
+ /**
* Show the controller on screen. It will go away
* automatically after 'timeout' milliseconds of inactivity.
* @param timeout The timeout in milliseconds. Use 0 to show
@@ -259,6 +282,7 @@ public class MediaController extends FrameLayout {
if (!mShowing && mAnchor != null) {
setProgress();
+ disableUnsupportedButtons();
int [] anchorpos = new int[2];
mAnchor.getLocationOnScreen(anchorpos);
@@ -421,17 +445,13 @@ public class MediaController extends FrameLayout {
};
private void updatePausePlay() {
- if (mRoot == null)
- return;
-
- ImageButton button = (ImageButton) mRoot.findViewById(com.android.internal.R.id.pause);
- if (button == null)
+ if (mRoot == null || mPauseButton == null)
return;
if (mPlayer.isPlaying()) {
- button.setImageResource(com.android.internal.R.drawable.ic_media_pause);
+ mPauseButton.setImageResource(com.android.internal.R.drawable.ic_media_pause);
} else {
- button.setImageResource(com.android.internal.R.drawable.ic_media_play);
+ mPauseButton.setImageResource(com.android.internal.R.drawable.ic_media_play);
}
}
@@ -516,7 +536,7 @@ public class MediaController extends FrameLayout {
if (mProgress != null) {
mProgress.setEnabled(enabled);
}
-
+ disableUnsupportedButtons();
super.setEnabled(enabled);
}
@@ -579,5 +599,8 @@ public class MediaController extends FrameLayout {
void seekTo(int pos);
boolean isPlaying();
int getBufferPercentage();
- };
+ boolean canPause();
+ boolean canSeekBackward();
+ boolean canSeekForward();
+ }
}
diff --git a/core/java/android/widget/VideoView.java b/core/java/android/widget/VideoView.java
index 5bc2507..e60ff25 100644
--- a/core/java/android/widget/VideoView.java
+++ b/core/java/android/widget/VideoView.java
@@ -23,6 +23,7 @@ import android.content.Intent;
import android.content.res.Resources;
import android.media.AudioManager;
import android.media.MediaPlayer;
+import android.media.Metadata;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaPlayer.OnErrorListener;
import android.net.Uri;
@@ -34,7 +35,7 @@ import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
-import android.widget.MediaController.MediaPlayerControl;
+import android.widget.MediaController.*;
import java.io.IOException;
@@ -81,6 +82,9 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
private int mCurrentBufferPercentage;
private OnErrorListener mOnErrorListener;
private int mSeekWhenPrepared; // recording the seek position while preparing
+ private boolean mCanPause;
+ private boolean mCanSeekBack;
+ private boolean mCanSeekForward;
public VideoView(Context context) {
super(context);
@@ -259,6 +263,17 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
MediaPlayer.OnPreparedListener mPreparedListener = new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp) {
mCurrentState = STATE_PREPARED;
+
+ // Get the capabilities of the player for this stream
+ Metadata data = mp.getMetadata(MediaPlayer.METADATA_ALL,
+ MediaPlayer.BYPASS_METADATA_FILTER);
+ mCanPause = !data.has(Metadata.PAUSE_AVAILABLE)
+ || data.getBoolean(Metadata.PAUSE_AVAILABLE);
+ mCanSeekBack = !data.has(Metadata.SEEK_BACKWARD_AVAILABLE)
+ || data.getBoolean(Metadata.SEEK_BACKWARD_AVAILABLE);
+ mCanSeekForward = !data.has(Metadata.SEEK_FORWARD_AVAILABLE)
+ || data.getBoolean(Metadata.SEEK_FORWARD_AVAILABLE);
+
if (mOnPreparedListener != null) {
mOnPreparedListener.onPrepared(mMediaPlayer);
}
@@ -267,6 +282,7 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
}
mVideoWidth = mp.getVideoWidth();
mVideoHeight = mp.getVideoHeight();
+
int seekToPosition = mSeekWhenPrepared; // mSeekWhenPrepared may be changed after seekTo() call
if (seekToPosition != 0) {
seekTo(seekToPosition);
@@ -580,4 +596,16 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
mCurrentState != STATE_IDLE &&
mCurrentState != STATE_PREPARING);
}
+
+ public boolean canPause() {
+ return mCanPause;
+ }
+
+ public boolean canSeekBackward() {
+ return mCanSeekBack;
+ }
+
+ public boolean canSeekForward() {
+ return mCanSeekForward;
+ }
}