[Android] VideoPlayer: safer changeAudioFocus
Thomas Guillem
git at videolan.org
Tue Mar 17 11:33:47 CET 2015
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Mar 17 10:06:18 2015 +0100| [dabacdf675a62cde497ee13ff8fdcdbfe02458cf] | committer: Thomas Guillem
VideoPlayer: safer changeAudioFocus
It won't do anything if stopped or started a second time
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=dabacdf675a62cde497ee13ff8fdcdbfe02458cf
---
.../vlc/gui/video/VideoPlayerActivity.java | 61 ++++++++++----------
1 file changed, 30 insertions(+), 31 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index 5074454..3cd325a 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -1203,41 +1203,40 @@ public class VideoPlayerActivity extends ActionBarActivity implements IVideoPlay
if(!LibVlcUtil.isFroyoOrLater()) // NOP if not supported
return AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
- if (mAudioFocusListener == null) {
- mAudioFocusListener = new OnAudioFocusChangeListener() {
- @Override
- public void onAudioFocusChange(int focusChange) {
+ mLostFocus = false;
+ int result;
+ if(acquire) {
+ if (mAudioFocusListener != null) {
+ mAudioFocusListener = new OnAudioFocusChangeListener() {
+ @Override
+ public void onAudioFocusChange(int focusChange) {
/*
* Pause playback during alerts and notifications
*/
- switch (focusChange)
- {
- case AudioManager.AUDIOFOCUS_LOSS:
- case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
- case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
- if (mLibVLC.isPlaying()) {
- mLibVLC.pause();
- mLostFocus = true;
- }
- break;
- case AudioManager.AUDIOFOCUS_GAIN:
- case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
- case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
- if (!mLibVLC.isPlaying() && mLostFocus)
- mLibVLC.play();
- mLostFocus = false;
- break;
+ switch (focusChange) {
+ case AudioManager.AUDIOFOCUS_LOSS:
+ case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
+ case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
+ if (mLibVLC.isPlaying()) {
+ mLibVLC.pause();
+ mLostFocus = true;
+ }
+ break;
+ case AudioManager.AUDIOFOCUS_GAIN:
+ case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT:
+ case AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK:
+ if (!mLibVLC.isPlaying() && mLostFocus)
+ mLibVLC.play();
+ mLostFocus = false;
+ break;
+ }
}
- }
- };
- }
-
- mLostFocus = false;
- int result;
- if(acquire) {
- result = mAudioManager.requestAudioFocus(mAudioFocusListener,
- AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
- mAudioManager.setParameters("bgm_state=true");
+ };
+ result = mAudioManager.requestAudioFocus(mAudioFocusListener,
+ AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
+ mAudioManager.setParameters("bgm_state=true");
+ } else
+ result = AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
}
else {
if (mAudioManager != null && mAudioFocusListener != null) {
More information about the Android
mailing list