[Android] VideoPlayer: simplify AudioManager code
Jean-Baptiste Kempf
git at videolan.org
Tue Jul 8 23:32:39 CEST 2014
vlc-ports/android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Tue Jul 8 23:12:09 2014 +0200| [606a53a492d3cb0a0c8dd1b42a3d313077a86d00] | committer: Jean-Baptiste Kempf
VideoPlayer: simplify AudioManager code
changeAudioFocus will now return the status, and the DualAudio is set
after the requestAudioFocus
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=606a53a492d3cb0a0c8dd1b42a3d313077a86d00
---
.../vlc/gui/video/VideoPlayerActivity.java | 24 ++++++++++++--------
1 file changed, 14 insertions(+), 10 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 a06eb4f..133776e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -501,7 +501,6 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
Log.i(TAG, "Dismissing presentation because the activity is no longer visible.");
mPresentation.dismiss();
mPresentation = null;
- mAudioManager.setParameters("bgm_state=false");
}
}
@@ -772,9 +771,9 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
}
@TargetApi(Build.VERSION_CODES.FROYO)
- private void changeAudioFocus(boolean gain) {
+ private int changeAudioFocus(boolean acquire) {
if(!LibVlcUtil.isFroyoOrLater()) // NOP if not supported
- return;
+ return AudioManager.AUDIOFOCUS_REQUEST_GRANTED;
if (mAudioFocusListener == null) {
mAudioFocusListener = new OnAudioFocusChangeListener() {
@@ -802,11 +801,18 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
};
}
- AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
- if(gain)
- am.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
- else
- am.abandonAudioFocus(mAudioFocusListener);
+ int result;
+ if(acquire) {
+ result = mAudioManager.requestAudioFocus(mAudioFocusListener,
+ AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
+ mAudioManager.setParameters("bgm_state=true");
+ }
+ else {
+ result = mAudioManager.abandonAudioFocus(mAudioFocusListener);
+ mAudioManager.setParameters("bgm_state=false");
+ }
+
+ return result;
}
/**
@@ -2093,7 +2099,6 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
mPresentation.setOnDismissListener(mOnDismissListener);
try {
mPresentation.show();
- mAudioManager.setParameters("bgm_state=true");
} catch (WindowManager.InvalidDisplayException ex) {
Log.w(TAG, "Couldn't show presentation! Display was removed in "
+ "the meantime.", ex);
@@ -2115,7 +2120,6 @@ public class VideoPlayerActivity extends Activity implements IVideoPlayer {
finish(); //TODO restore the video on the new display instead of closing
if (mPresentation != null) mPresentation.dismiss();
mPresentation = null;
- mAudioManager.setParameters("bgm_state=false");
}
/**
More information about the Android
mailing list