From cf4aba93e4c67395c53bc758138c0c16658093c3 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Fri, 16 May 2014 16:47:41 +0200 Subject: Android: fix media player's volume. - Preserve the volume when changing the current media. - Don't actually set a new volume when the media player is muted. Intead, save the value to apply it when setMuted(false) is called. Change-Id: I829eb280406ea35ff82a0c2638b2d19cf1d90643 Reviewed-by: Christian Stromme --- .../android/multimedia/QtAndroidMediaPlayer.java | 29 ++++++++++++++-------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/plugins/android') diff --git a/src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java b/src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java index 01f260910..32d3496ee 100644 --- a/src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java +++ b/src/plugins/android/jar/src/org/qtproject/qt5/android/multimedia/QtAndroidMediaPlayer.java @@ -248,6 +248,8 @@ public class QtAndroidMediaPlayer if (mMediaPlayer == null) { mMediaPlayer = new MediaPlayer(); setState(State.Idle); + // Make sure the new media player has the volume that was set on the QMediaPlayer + setVolumeHelper(mMuted ? 0 : mVolume); } } @@ -476,6 +478,20 @@ public class QtAndroidMediaPlayer } public void setVolume(int volume) + { + if (volume < 0) + volume = 0; + + if (volume > 100) + volume = 100; + + mVolume = volume; + + if (!mMuted) + setVolumeHelper(mVolume); + } + + private void setVolumeHelper(int volume) { if ((mState & (State.Idle | State.Initialized @@ -487,18 +503,9 @@ public class QtAndroidMediaPlayer return; } - if (volume < 0) - volume = 0; - - if (volume > 100) - volume = 100; - - float newVolume = adjustVolume(volume); - try { + float newVolume = adjustVolume(volume); mMediaPlayer.setVolume(newVolume, newVolume); - if (!mMuted) - mVolume = volume; } catch (final IllegalStateException e) { Log.d(TAG, "" + e.getMessage()); } @@ -528,7 +535,7 @@ public class QtAndroidMediaPlayer public void mute(final boolean mute) { mMuted = mute; - setVolume(mute ? 0 : mVolume); + setVolumeHelper(mute ? 0 : mVolume); } public boolean isMuted() -- cgit v1.2.1