Merge "Add VideoView.getAudioSessionId()" into jb-mr2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
86e0b491d1
@ -29775,6 +29775,7 @@ package android.widget {
|
|||||||
method public abstract boolean canPause();
|
method public abstract boolean canPause();
|
||||||
method public abstract boolean canSeekBackward();
|
method public abstract boolean canSeekBackward();
|
||||||
method public abstract boolean canSeekForward();
|
method public abstract boolean canSeekForward();
|
||||||
|
method public abstract int getAudioSessionId();
|
||||||
method public abstract int getBufferPercentage();
|
method public abstract int getBufferPercentage();
|
||||||
method public abstract int getCurrentPosition();
|
method public abstract int getCurrentPosition();
|
||||||
method public abstract int getDuration();
|
method public abstract int getDuration();
|
||||||
@ -30879,6 +30880,7 @@ package android.widget {
|
|||||||
method public boolean canPause();
|
method public boolean canPause();
|
||||||
method public boolean canSeekBackward();
|
method public boolean canSeekBackward();
|
||||||
method public boolean canSeekForward();
|
method public boolean canSeekForward();
|
||||||
|
method public int getAudioSessionId();
|
||||||
method public int getBufferPercentage();
|
method public int getBufferPercentage();
|
||||||
method public int getCurrentPosition();
|
method public int getCurrentPosition();
|
||||||
method public int getDuration();
|
method public int getDuration();
|
||||||
|
@ -340,6 +340,14 @@ public class HTML5VideoFullScreen extends HTML5VideoView
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAudioSessionId() {
|
||||||
|
if (mPlayer == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return mPlayer.getAudioSessionId();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showControllerInFullScreen() {
|
public void showControllerInFullScreen() {
|
||||||
if (mMediaController != null) {
|
if (mMediaController != null) {
|
||||||
|
@ -677,5 +677,12 @@ public class MediaController extends FrameLayout {
|
|||||||
boolean canPause();
|
boolean canPause();
|
||||||
boolean canSeekBackward();
|
boolean canSeekBackward();
|
||||||
boolean canSeekForward();
|
boolean canSeekForward();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the audio session id for the player used by this VideoView. This can be used to
|
||||||
|
* apply audio effects to the audio track of a video.
|
||||||
|
* @return The audio session, or 0 if there was an error.
|
||||||
|
*/
|
||||||
|
int getAudioSessionId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,6 @@ import android.view.MotionEvent;
|
|||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.MeasureSpec;
|
|
||||||
import android.view.accessibility.AccessibilityEvent;
|
import android.view.accessibility.AccessibilityEvent;
|
||||||
import android.view.accessibility.AccessibilityNodeInfo;
|
import android.view.accessibility.AccessibilityNodeInfo;
|
||||||
import android.widget.MediaController.MediaPlayerControl;
|
import android.widget.MediaController.MediaPlayerControl;
|
||||||
@ -76,6 +75,7 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
|
|||||||
// All the stuff we need for playing and showing a video
|
// All the stuff we need for playing and showing a video
|
||||||
private SurfaceHolder mSurfaceHolder = null;
|
private SurfaceHolder mSurfaceHolder = null;
|
||||||
private MediaPlayer mMediaPlayer = null;
|
private MediaPlayer mMediaPlayer = null;
|
||||||
|
private int mAudioSession;
|
||||||
private int mVideoWidth;
|
private int mVideoWidth;
|
||||||
private int mVideoHeight;
|
private int mVideoHeight;
|
||||||
private int mSurfaceWidth;
|
private int mSurfaceWidth;
|
||||||
@ -244,6 +244,11 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
|
|||||||
release(false);
|
release(false);
|
||||||
try {
|
try {
|
||||||
mMediaPlayer = new MediaPlayer();
|
mMediaPlayer = new MediaPlayer();
|
||||||
|
if (mAudioSession != 0) {
|
||||||
|
mMediaPlayer.setAudioSessionId(mAudioSession);
|
||||||
|
} else {
|
||||||
|
mAudioSession = mMediaPlayer.getAudioSessionId();
|
||||||
|
}
|
||||||
mMediaPlayer.setOnPreparedListener(mPreparedListener);
|
mMediaPlayer.setOnPreparedListener(mPreparedListener);
|
||||||
mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
|
mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
|
||||||
mMediaPlayer.setOnCompletionListener(mCompletionListener);
|
mMediaPlayer.setOnCompletionListener(mCompletionListener);
|
||||||
@ -598,6 +603,7 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
if (isInPlaybackState()) {
|
if (isInPlaybackState()) {
|
||||||
mMediaPlayer.start();
|
mMediaPlayer.start();
|
||||||
@ -606,6 +612,7 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
|
|||||||
mTargetState = STATE_PLAYING;
|
mTargetState = STATE_PLAYING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void pause() {
|
public void pause() {
|
||||||
if (isInPlaybackState()) {
|
if (isInPlaybackState()) {
|
||||||
if (mMediaPlayer.isPlaying()) {
|
if (mMediaPlayer.isPlaying()) {
|
||||||
@ -624,6 +631,7 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
|
|||||||
openVideo();
|
openVideo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getDuration() {
|
public int getDuration() {
|
||||||
if (isInPlaybackState()) {
|
if (isInPlaybackState()) {
|
||||||
return mMediaPlayer.getDuration();
|
return mMediaPlayer.getDuration();
|
||||||
@ -632,6 +640,7 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getCurrentPosition() {
|
public int getCurrentPosition() {
|
||||||
if (isInPlaybackState()) {
|
if (isInPlaybackState()) {
|
||||||
return mMediaPlayer.getCurrentPosition();
|
return mMediaPlayer.getCurrentPosition();
|
||||||
@ -639,6 +648,7 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void seekTo(int msec) {
|
public void seekTo(int msec) {
|
||||||
if (isInPlaybackState()) {
|
if (isInPlaybackState()) {
|
||||||
mMediaPlayer.seekTo(msec);
|
mMediaPlayer.seekTo(msec);
|
||||||
@ -648,10 +658,12 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean isPlaying() {
|
public boolean isPlaying() {
|
||||||
return isInPlaybackState() && mMediaPlayer.isPlaying();
|
return isInPlaybackState() && mMediaPlayer.isPlaying();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getBufferPercentage() {
|
public int getBufferPercentage() {
|
||||||
if (mMediaPlayer != null) {
|
if (mMediaPlayer != null) {
|
||||||
return mCurrentBufferPercentage;
|
return mCurrentBufferPercentage;
|
||||||
@ -666,15 +678,28 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
|
|||||||
mCurrentState != STATE_PREPARING);
|
mCurrentState != STATE_PREPARING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean canPause() {
|
public boolean canPause() {
|
||||||
return mCanPause;
|
return mCanPause;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean canSeekBackward() {
|
public boolean canSeekBackward() {
|
||||||
return mCanSeekBack;
|
return mCanSeekBack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean canSeekForward() {
|
public boolean canSeekForward() {
|
||||||
return mCanSeekForward;
|
return mCanSeekForward;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAudioSessionId() {
|
||||||
|
if (mAudioSession == 0) {
|
||||||
|
MediaPlayer foo = new MediaPlayer();
|
||||||
|
mAudioSession = foo.getAudioSessionId();
|
||||||
|
foo.release();
|
||||||
|
}
|
||||||
|
return mAudioSession;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user