Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 13bfebd6 authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Add VideoView.getAudioSessionId()

This lets apps get the audio session id of the video being played, so
they can apply effects to the audio track.
b/8767565

Change-Id: Iaa39d97d0b6fb528ed04b52d579afa58444ebcfe
parent 2c76016c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -29772,6 +29772,7 @@ package android.widget {
    method public abstract boolean canPause();
    method public abstract boolean canSeekBackward();
    method public abstract boolean canSeekForward();
    method public abstract int getAudioSessionId();
    method public abstract int getBufferPercentage();
    method public abstract int getCurrentPosition();
    method public abstract int getDuration();
@@ -30876,6 +30877,7 @@ package android.widget {
    method public boolean canPause();
    method public boolean canSeekBackward();
    method public boolean canSeekForward();
    method public int getAudioSessionId();
    method public int getBufferPercentage();
    method public int getCurrentPosition();
    method public int getDuration();
+8 −0
Original line number Diff line number Diff line
@@ -340,6 +340,14 @@ public class HTML5VideoFullScreen extends HTML5VideoView
    return 0;
    }

    @Override
    public int getAudioSessionId() {
        if (mPlayer == null) {
            return 0;
        }
        return mPlayer.getAudioSessionId();
    }

    @Override
    public void showControllerInFullScreen() {
        if (mMediaController != null) {
+7 −0
Original line number Diff line number Diff line
@@ -677,5 +677,12 @@ public class MediaController extends FrameLayout {
        boolean canPause();
        boolean canSeekBackward();
        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();
    }
}
+26 −1
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityNodeInfo;
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
    private SurfaceHolder mSurfaceHolder = null;
    private MediaPlayer mMediaPlayer = null;
    private int         mAudioSession;
    private int         mVideoWidth;
    private int         mVideoHeight;
    private int         mSurfaceWidth;
@@ -244,6 +244,11 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
        release(false);
        try {
            mMediaPlayer = new MediaPlayer();
            if (mAudioSession != 0) {
                mMediaPlayer.setAudioSessionId(mAudioSession);
            } else {
                mAudioSession = mMediaPlayer.getAudioSessionId();
            }
            mMediaPlayer.setOnPreparedListener(mPreparedListener);
            mMediaPlayer.setOnVideoSizeChangedListener(mSizeChangedListener);
            mMediaPlayer.setOnCompletionListener(mCompletionListener);
@@ -598,6 +603,7 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
        }
    }

    @Override
    public void start() {
        if (isInPlaybackState()) {
            mMediaPlayer.start();
@@ -606,6 +612,7 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
        mTargetState = STATE_PLAYING;
    }

    @Override
    public void pause() {
        if (isInPlaybackState()) {
            if (mMediaPlayer.isPlaying()) {
@@ -624,6 +631,7 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
        openVideo();
    }

    @Override
    public int getDuration() {
        if (isInPlaybackState()) {
            return mMediaPlayer.getDuration();
@@ -632,6 +640,7 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
        return -1;
    }

    @Override
    public int getCurrentPosition() {
        if (isInPlaybackState()) {
            return mMediaPlayer.getCurrentPosition();
@@ -639,6 +648,7 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
        return 0;
    }

    @Override
    public void seekTo(int msec) {
        if (isInPlaybackState()) {
            mMediaPlayer.seekTo(msec);
@@ -648,10 +658,12 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
        }
    }

    @Override
    public boolean isPlaying() {
        return isInPlaybackState() && mMediaPlayer.isPlaying();
    }

    @Override
    public int getBufferPercentage() {
        if (mMediaPlayer != null) {
            return mCurrentBufferPercentage;
@@ -666,15 +678,28 @@ public class VideoView extends SurfaceView implements MediaPlayerControl {
                mCurrentState != STATE_PREPARING);
    }

    @Override
    public boolean canPause() {
        return mCanPause;
    }

    @Override
    public boolean canSeekBackward() {
        return mCanSeekBack;
    }

    @Override
    public boolean canSeekForward() {
        return mCanSeekForward;
    }

    @Override
    public int getAudioSessionId() {
        if (mAudioSession == 0) {
            MediaPlayer foo = new MediaPlayer();
            mAudioSession = foo.getAudioSessionId();
            foo.release();
        }
        return mAudioSession;
    }
}