diff options
-rwxr-xr-x | src/com/android/gallery3d/app/MoviePlayer.java | 45 | ||||
-rw-r--r-- | src/com/android/gallery3d/app/PhotoPage.java | 4 | ||||
-rw-r--r-- | src/com/android/gallery3d/util/GalleryUtils.java | 20 | ||||
-rw-r--r-- | src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java | 22 |
4 files changed, 75 insertions, 16 deletions
diff --git a/src/com/android/gallery3d/app/MoviePlayer.java b/src/com/android/gallery3d/app/MoviePlayer.java index 8ae29c067..d24058598 100755 --- a/src/com/android/gallery3d/app/MoviePlayer.java +++ b/src/com/android/gallery3d/app/MoviePlayer.java @@ -221,19 +221,31 @@ public class MoviePlayer implements } }; - private AudioManager.OnAudioFocusChangeListener mAudioFocusListener = - new AudioManager.OnAudioFocusChangeListener() { + private CodeauroraVideoView.AudioFocusChangeListener mAudioFocusListener = + new CodeauroraVideoView.AudioFocusChangeListener() { + @Override + public void onAudioFocusRequestFailed() { + Log.d(TAG, "pause video because onAudioFocusRequestFailed."); + onPauseVideo(); + } + + @Override public void onAudioFocusChange(int focusChange) { switch (focusChange) { case AudioManager.AUDIOFOCUS_GAIN: - if (mPausedByTransientLossOfFocus) { + boolean isTargetPlaying = (mVideoView != null && + mVideoView.isTargetPlaying()); + Log.d(TAG, "AUDIOFOCUS_GAIN isTargetPlaying : " + isTargetPlaying); + if (mPausedByTransientLossOfFocus || isTargetPlaying) { onPlayVideo(); mPausedByTransientLossOfFocus = false; } break; case AudioManager.AUDIOFOCUS_LOSS: case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT: - if (mVideoView != null && mVideoView.isPlaying()) { + boolean isPlaying = (mVideoView != null && mVideoView.isPlaying()); + Log.d(TAG, "AUDIOFOCUS_LOSS isPlaying : " + isPlaying); + if (isPlaying) { onPauseVideo(); mPausedByTransientLossOfFocus = true; } @@ -643,14 +655,21 @@ public class MoviePlayer implements doStartVideo(enableFasten, position, duration, true); } - private void playVideo() { + private boolean playVideo() { if (LOG) { Log.v(TAG, "playVideo()"); } + + if (GalleryUtils.isTelephonyCallInProgress()) { + Log.w(TAG, "CS/CSVT Call is in progress, can't play video"); + return false; + } + mTState = TState.PLAYING; mVideoView.start(); mController.showPlaying(); setProgress(); + return true; } private void pauseVideo() { @@ -717,17 +736,19 @@ public class MoviePlayer implements } private void onPlayVideo() { - playVideo(); - //set view disabled(play/pause asynchronous processing) - mController.setViewEnabled(true); - if (mControllerRewindAndForwardExt != null) { - mControllerRewindAndForwardExt.showControllerButtonsView(mPlayerExt - .canStop(), false, false); + boolean result = playVideo(); + if (result) { + //set view disabled(play/pause asynchronous processing) + mController.setViewEnabled(true); + if (mControllerRewindAndForwardExt != null) { + mControllerRewindAndForwardExt.showControllerButtonsView(mPlayerExt + .canStop(), false, false); + } } } private void onPauseVideo() { - if (mVideoView.canPause()) { + if (mVideoView != null && mVideoView.canPause()) { pauseVideo(); //set view disabled(play/pause asynchronous processing) mController.setViewEnabled(true); diff --git a/src/com/android/gallery3d/app/PhotoPage.java b/src/com/android/gallery3d/app/PhotoPage.java index 4e61df9c7..fb39257b6 100644 --- a/src/com/android/gallery3d/app/PhotoPage.java +++ b/src/com/android/gallery3d/app/PhotoPage.java @@ -1372,6 +1372,10 @@ public abstract class PhotoPage extends ActivityState implements } public void playVideo(Activity activity, Uri uri, String title) { + if (GalleryUtils.isTelephonyCallInProgress()) { + Log.w(TAG, "CS/CSVT Call is in progress, can't play video"); + return; + } try { Intent intent = new Intent(Intent.ACTION_VIEW) .setDataAndType(uri, "video/*") diff --git a/src/com/android/gallery3d/util/GalleryUtils.java b/src/com/android/gallery3d/util/GalleryUtils.java index 0a3540e9c..009da6cbe 100644 --- a/src/com/android/gallery3d/util/GalleryUtils.java +++ b/src/com/android/gallery3d/util/GalleryUtils.java @@ -34,6 +34,8 @@ import android.os.Environment; import android.os.StatFs; import android.preference.PreferenceManager; import android.provider.MediaStore; +import android.telephony.SubscriptionManager; +import android.telephony.TelephonyManager; import android.util.DisplayMetrics; import android.util.Log; import android.view.WindowManager; @@ -436,4 +438,22 @@ public class GalleryUtils { ed.putInt(name, value); ed.commit(); } + + public static boolean isTelephonyCallInProgress() { + TelephonyManager telephonyManager = TelephonyManager.getDefault(); + + int count = telephonyManager.getPhoneCount(); + for (int i = 0; i < count; i++) { + int[] subId = SubscriptionManager.getSubId(i); + if (subId != null && subId.length > 0) { + int telephony_state = telephonyManager.getCallState(subId[0]); + + if (telephony_state == TelephonyManager.CALL_STATE_OFFHOOK + || telephony_state == TelephonyManager.CALL_STATE_RINGING) { + return true; + } + } + } + return false; + } } diff --git a/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java b/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java index e3f441e95..c6956e68c 100644 --- a/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java +++ b/src/org/codeaurora/gallery3d/video/CodeauroraVideoView.java @@ -98,7 +98,11 @@ public class CodeauroraVideoView extends SurfaceView implements MediaPlayerContr private boolean mIsShowDialog = false; private boolean mErrorDialogShowing = false; private KeyguardManager mKeyguardManager; - private AudioManager.OnAudioFocusChangeListener mAudioFocusListener; + private AudioFocusChangeListener mAudioFocusListener; + + public interface AudioFocusChangeListener extends AudioManager.OnAudioFocusChangeListener { + public void onAudioFocusRequestFailed(); + } private final Handler mHandler = new Handler() { public void handleMessage(final Message msg) { @@ -622,7 +626,7 @@ public class CodeauroraVideoView extends SurfaceView implements MediaPlayerContr mOnInfoListener = l; } - public void setOnAudioFocusChangeListener(AudioManager.OnAudioFocusChangeListener l) { + public void setOnAudioFocusChangeListener(AudioFocusChangeListener l) { mAudioFocusListener = l; } @@ -778,8 +782,18 @@ public class CodeauroraVideoView extends SurfaceView implements MediaPlayerContr public void start() { if (mIsShowDialog) return; if (isInPlaybackState()) { - mMediaPlayer.start(); - mCurrentState = STATE_PLAYING; + AudioManager am = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); + int result = am.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, + AudioManager.AUDIOFOCUS_GAIN); + if (result != AudioManager.AUDIOFOCUS_REQUEST_FAILED) { + mMediaPlayer.start(); + mCurrentState = STATE_PLAYING; + } else { + Log.w(TAG, "requestAudioFocus failed."); + if (mAudioFocusListener != null) { + mAudioFocusListener.onAudioFocusRequestFailed(); + } + } } mTargetState = STATE_PLAYING; } |