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

Commit e0321526 authored by Marco Nelissen's avatar Marco Nelissen Committed by Mangesh Ghiware
Browse files

Enable virtualization

When the Intent says to virtualize, and the right virtualizer is
present on the device, enable virtualization.

Bug: 8767565
Bug: 10727216

Change-Id: I8a98404b21c434966b7ae2dc341eb38f2a47eef2
(cherry picked from commit af6b0d2c)
parent e10fd688
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.audiofx.AudioEffect;
import android.media.audiofx.Virtualizer;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -66,6 +68,7 @@ public class MoviePlayer implements
    private static final String CMDNAME = "command";
    private static final String CMDPAUSE = "pause";

    private static final String VIRTUALIZE_EXTRA = "virtualize";
    private static final long BLACK_TIMEOUT = 500;

    // If we resume the acitivty with in RESUMEABLE_TIMEOUT, we will keep playing.
@@ -92,6 +95,8 @@ public class MoviePlayer implements
    // If the time bar is visible.
    private boolean mShowing;

    private Virtualizer mVirtualizer;

    private final Runnable mPlayingChecker = new Runnable() {
        @Override
        public void run() {
@@ -127,6 +132,18 @@ public class MoviePlayer implements
        mVideoView.setOnErrorListener(this);
        mVideoView.setOnCompletionListener(this);
        mVideoView.setVideoURI(mUri);

        Intent ai = movieActivity.getIntent();
        boolean virtualize = ai.getBooleanExtra(VIRTUALIZE_EXTRA, false);
        if (virtualize) {
            int session = mVideoView.getAudioSessionId();
            if (session != 0) {
                mVirtualizer = new Virtualizer(0, session);
                mVirtualizer.setEnabled(true);
            } else {
                Log.w(TAG, "no audio session to virtualize");
            }
        }
        mVideoView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
@@ -280,6 +297,10 @@ public class MoviePlayer implements
    }

    public void onDestroy() {
        if (mVirtualizer != null) {
            mVirtualizer.release();
            mVirtualizer = null;
        }
        mVideoView.stopPlayback();
        mAudioBecomingNoisyReceiver.unregister();
    }