Commit dabacdf6 authored by Thomas Guillem's avatar Thomas Guillem
Browse files

VideoPlayer: safer changeAudioFocus

It won't do anything if stopped or started a second time
parent 267cfaf6
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment