diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2016-03-25 08:31:24 -0400 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2016-03-25 08:31:24 -0400 |
commit | a2c1d6f9f7cab759f37d1d180170e5e1624865a5 (patch) | |
tree | 89319281500c5ee7ea021d856203541a02843ff2 | |
parent | ebaa19a4dd6208d152040e56dddd7416551e098b (diff) | |
parent | 383a833c30fa13f18a5e58319f2045d3c0f08ea8 (diff) | |
download | AntennaPod-a2c1d6f9f7cab759f37d1d180170e5e1624865a5.zip |
Merge pull request #1820 from mfietz/issue/1793-player-switch
Switch audio player implementation immediately
11 files changed, 168 insertions, 40 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java index 7862e986d..68a0ecd08 100644 --- a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java +++ b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceMediaPlayerTest.java @@ -53,7 +53,10 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { super.setUp(); assertionError = null; + final Context context = getInstrumentation().getTargetContext(); + // create new database + PodDBAdapter.init(context); PodDBAdapter.deleteDatabase(); PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); @@ -62,7 +65,6 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { httpServer = new HTTPBin(); httpServer.start(); - final Context context = getInstrumentation().getTargetContext(); File cacheDir = context.getExternalFilesDir("testFiles"); if (cacheDir == null) cacheDir = context.getExternalFilesDir("testFiles"); @@ -168,6 +170,11 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } @Override + public void setSpeedAbilityChanged() { + + } + + @Override public void onBufferingUpdate(int percent) { } @@ -237,6 +244,11 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } @Override + public void setSpeedAbilityChanged() { + + } + + @Override public void onBufferingUpdate(int percent) { } @@ -309,6 +321,11 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } @Override + public void setSpeedAbilityChanged() { + + } + + @Override public void onBufferingUpdate(int percent) { } @@ -382,6 +399,11 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } @Override + public void setSpeedAbilityChanged() { + + } + + @Override public void onBufferingUpdate(int percent) { } @@ -449,6 +471,11 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } @Override + public void setSpeedAbilityChanged() { + + } + + @Override public void onBufferingUpdate(int percent) { } @@ -517,6 +544,11 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } @Override + public void setSpeedAbilityChanged() { + + } + + @Override public void onBufferingUpdate(int percent) { } @@ -587,6 +619,11 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } @Override + public void setSpeedAbilityChanged() { + + } + + @Override public void onBufferingUpdate(int percent) { } @@ -660,6 +697,11 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } @Override + public void setSpeedAbilityChanged() { + + } + + @Override public void onBufferingUpdate(int percent) { } @@ -708,6 +750,11 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } @Override + public void setSpeedAbilityChanged() { + + } + + @Override public void onBufferingUpdate(int percent) { } @@ -776,6 +823,11 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } @Override + public void setSpeedAbilityChanged() { + + } + + @Override public void onBufferingUpdate(int percent) { } @@ -881,6 +933,11 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } @Override + public void setSpeedAbilityChanged() { + + } + + @Override public void onBufferingUpdate(int percent) { } @@ -963,6 +1020,11 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } @Override + public void setSpeedAbilityChanged() { + + } + + @Override public void onBufferingUpdate(int percent) { } @@ -1057,6 +1119,11 @@ public class PlaybackServiceMediaPlayerTest extends InstrumentationTestCase { } @Override + public void setSpeedAbilityChanged() { + + } + + @Override public void onBufferingUpdate(int percent) { } diff --git a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java index 5c3d32960..6ab6e5c61 100644 --- a/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java +++ b/app/src/androidTest/java/de/test/antennapod/service/playback/PlaybackServiceTaskManagerTest.java @@ -34,6 +34,7 @@ public class PlaybackServiceTaskManagerTest extends InstrumentationTestCase { super.setUp(); // create new database + PodDBAdapter.init(getInstrumentation().getTargetContext()); PodDBAdapter.deleteDatabase(); PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); diff --git a/app/src/androidTest/java/de/test/antennapod/storage/DBNullCleanupAlgorithmTest.java b/app/src/androidTest/java/de/test/antennapod/storage/DBNullCleanupAlgorithmTest.java index 74b34a176..7925941ec 100644 --- a/app/src/androidTest/java/de/test/antennapod/storage/DBNullCleanupAlgorithmTest.java +++ b/app/src/androidTest/java/de/test/antennapod/storage/DBNullCleanupAlgorithmTest.java @@ -58,7 +58,7 @@ public class DBNullCleanupAlgorithmTest extends InstrumentationTestCase { assertTrue(destFolder.canWrite()); // create new database - PodDBAdapter.init(getInstrumentation().getTargetContext()); + PodDBAdapter.init(context); PodDBAdapter.deleteDatabase(); PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); diff --git a/app/src/androidTest/java/de/test/antennapod/storage/DBTasksTest.java b/app/src/androidTest/java/de/test/antennapod/storage/DBTasksTest.java index 3d4e78f8f..785d32e93 100644 --- a/app/src/androidTest/java/de/test/antennapod/storage/DBTasksTest.java +++ b/app/src/androidTest/java/de/test/antennapod/storage/DBTasksTest.java @@ -39,7 +39,7 @@ public class DBTasksTest extends InstrumentationTestCase { context = getInstrumentation().getTargetContext(); // create new database - PodDBAdapter.init(getInstrumentation().getTargetContext()); + PodDBAdapter.init(context); PodDBAdapter.deleteDatabase(); PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); diff --git a/app/src/androidTest/java/de/test/antennapod/ui/MainActivityTest.java b/app/src/androidTest/java/de/test/antennapod/ui/MainActivityTest.java index 4e214cf81..d4c9fa2f7 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/MainActivityTest.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/MainActivityTest.java @@ -41,10 +41,12 @@ public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActiv @Override protected void setUp() throws Exception { super.setUp(); - uiTestUtils = new UITestUtils(getInstrumentation().getTargetContext()); + Context context = getInstrumentation().getTargetContext(); + uiTestUtils = new UITestUtils(context); uiTestUtils.setup(); // create new database + PodDBAdapter.init(context); PodDBAdapter.deleteDatabase(); PodDBAdapter adapter = PodDBAdapter.getInstance(); adapter.open(); diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java index 50daf163f..4911f61bc 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java @@ -173,12 +173,21 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O super.setScreenOn(enable); MediaplayerActivity.this.setScreenOn(enable); } + + @Override + public void onSetSpeedAbilityChanged() { + MediaplayerActivity.this.onSetSpeedAbilityChanged(); + } }; + } + protected void onSetSpeedAbilityChanged() { + Log.d(TAG, "onSetSpeedAbilityChanged()"); + updatePlaybackSpeedButton(); } protected void onPlaybackSpeedChange() { - updateButPlaybackSpeed(); + updatePlaybackSpeedButtonText(); } protected void onServiceQueried() { @@ -628,25 +637,50 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O if (media != null) { onPositionObserverUpdate(); checkFavorite(); - if(butPlaybackSpeed != null) { - if (controller == null) { - butPlaybackSpeed.setVisibility(View.GONE); - } else { - butPlaybackSpeed.setVisibility(View.VISIBLE); - if (controller.canSetPlaybackSpeed()) { - ViewCompat.setAlpha(butPlaybackSpeed, 1.0f); - } else { - ViewCompat.setAlpha(butPlaybackSpeed, 0.5f); - } - } - updateButPlaybackSpeed(); - } + updatePlaybackSpeedButton(); return true; } else { return false; } } + private void updatePlaybackSpeedButton() { + if(butPlaybackSpeed == null) { + return; + } + if (controller == null) { + butPlaybackSpeed.setVisibility(View.GONE); + return; + } + updatePlaybackSpeedButtonText(); + ViewCompat.setAlpha(butPlaybackSpeed, controller.canSetPlaybackSpeed() ? 1.0f : 0.5f); + butPlaybackSpeed.setVisibility(View.VISIBLE); + } + + private void updatePlaybackSpeedButtonText() { + if(butPlaybackSpeed == null) { + return; + } + if (controller == null) { + butPlaybackSpeed.setVisibility(View.GONE); + return; + } + float speed = 1.0f; + if(controller.canSetPlaybackSpeed()) { + try { + // we can only retrieve the playback speed from the controller/playback service + // once mediaplayer has been initialized + speed = Float.parseFloat(UserPreferences.getPlaybackSpeed()); + } catch (NumberFormatException e) { + Log.e(TAG, Log.getStackTraceString(e)); + UserPreferences.setPlaybackSpeed(String.valueOf(speed)); + } + } + String speedStr = String.format("%.2fx", speed); + butPlaybackSpeed.setText(speedStr); + } + + protected void setupGUI() { setContentView(getContentViewResourceId()); sbPosition = (SeekBar) findViewById(R.id.sbPosition); @@ -874,20 +908,6 @@ public abstract class MediaplayerActivity extends AppCompatActivity implements O } } - private void updateButPlaybackSpeed() { - if (controller != null && butPlaybackSpeed != null) { - float speed = 1.0f; - try { - speed = Float.parseFloat(UserPreferences.getPlaybackSpeed()); - } catch(NumberFormatException e) { - Log.e(TAG, Log.getStackTraceString(e)); - UserPreferences.setPlaybackSpeed(String.valueOf(speed)); - } - String speedStr = String.format("%.2fx", speed); - butPlaybackSpeed.setText(speedStr); - } - } - @Override public void onStartTrackingTouch(SeekBar seekBar) { if (controller != null) { diff --git a/build.gradle b/build.gradle index 2d42a5759..046a9d4f9 100644 --- a/build.gradle +++ b/build.gradle @@ -59,7 +59,7 @@ project.ext { rxJavaVersion = "1.1.0" rxJavaRulesVersion = "1.1.0.0" - audioPlayerVersion = "v1.0.14" + audioPlayerVersion = "v1.0.16" } task wrapper(type: Wrapper) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 9ca05d1f7..729ea9e7a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -142,6 +142,11 @@ public class PlaybackService extends Service { public static final int NOTIFICATION_TYPE_PLAYBACK_SPEED_CHANGE = 8; /** + * Ability to set the playback speed has changed + */ + public static final int NOTIFICATION_TYPE_SET_SPEED_ABILITY_CHANGED = 9; + + /** * Returned by getPositionSafe() or getDurationSafe() if the playbackService * is in an invalid state. */ @@ -512,8 +517,11 @@ public class PlaybackService extends Service { @Override public void playbackSpeedChanged(float s) { - sendNotificationBroadcast( - NOTIFICATION_TYPE_PLAYBACK_SPEED_CHANGE, 0); + sendNotificationBroadcast(NOTIFICATION_TYPE_PLAYBACK_SPEED_CHANGE, 0); + } + + public void setSpeedAbilityChanged() { + sendNotificationBroadcast(NOTIFICATION_TYPE_SET_SPEED_ABILITY_CHANGED, 0); } @Override diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java index 3ab26eb22..aa51840a7 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackServiceMediaPlayer.java @@ -25,6 +25,8 @@ import android.view.WindowManager; import com.bumptech.glide.Glide; +import org.antennapod.audio.MediaPlayer; + import java.io.IOException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingDeque; @@ -1016,6 +1018,8 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre void playbackSpeedChanged(float s); + void setSpeedAbilityChanged(); + void onBufferingUpdate(int percent); boolean onMediaPlayerInfo(int code); @@ -1036,6 +1040,7 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre ((AudioPlayer) mp) .setOnBufferingUpdateListener(audioBufferingUpdateListener); ((AudioPlayer) mp).setOnInfoListener(audioInfoListener); + ((AudioPlayer) mp).setOnSpeedAdjustmentAvailableChangedListener(audioSetSpeedAbilityListener); } else { ((VideoPlayer) mp) .setOnCompletionListener(videoCompletionListener); @@ -1050,7 +1055,7 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre return mp; } - private final org.antennapod.audio.MediaPlayer.OnCompletionListener audioCompletionListener = + private final MediaPlayer.OnCompletionListener audioCompletionListener = mp -> genericOnCompletion(); private final android.media.MediaPlayer.OnCompletionListener videoCompletionListener = @@ -1060,7 +1065,7 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre endPlayback(false); } - private final org.antennapod.audio.MediaPlayer.OnBufferingUpdateListener audioBufferingUpdateListener = + private final MediaPlayer.OnBufferingUpdateListener audioBufferingUpdateListener = (mp, percent) -> genericOnBufferingUpdate(percent); private final android.media.MediaPlayer.OnBufferingUpdateListener videoBufferingUpdateListener = @@ -1070,7 +1075,7 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre callback.onBufferingUpdate(percent); } - private final org.antennapod.audio.MediaPlayer.OnInfoListener audioInfoListener = + private final MediaPlayer.OnInfoListener audioInfoListener = (mp, what, extra) -> genericInfoListener(what); private final android.media.MediaPlayer.OnInfoListener videoInfoListener = @@ -1080,7 +1085,16 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre return callback.onMediaPlayerInfo(what); } - private final org.antennapod.audio.MediaPlayer.OnErrorListener audioErrorListener = + private final MediaPlayer.OnSpeedAdjustmentAvailableChangedListener + audioSetSpeedAbilityListener = new MediaPlayer.OnSpeedAdjustmentAvailableChangedListener() { + @Override + public void onSpeedAdjustmentAvailableChanged(MediaPlayer arg0, boolean speedAdjustmentAvailable) { + callback.setSpeedAbilityChanged(); + } + }; + + + private final MediaPlayer.OnErrorListener audioErrorListener = (mp, what, extra) -> { if(mp.canFallback()) { mp.fallback(); @@ -1096,7 +1110,7 @@ public class PlaybackServiceMediaPlayer implements SharedPreferences.OnSharedPre return callback.onMediaPlayerError(inObj, what, extra); } - private final org.antennapod.audio.MediaPlayer.OnSeekCompleteListener audioSeekCompleteListener = + private final MediaPlayer.OnSeekCompleteListener audioSeekCompleteListener = mp -> genericSeekCompleteListener(); private final android.media.MediaPlayer.OnSeekCompleteListener videoSeekCompleteListener = diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/AudioPlayer.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/AudioPlayer.java index f0850e6df..846733882 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/AudioPlayer.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/AudioPlayer.java @@ -1,8 +1,11 @@ package de.danoeh.antennapod.core.util.playback; import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; import android.util.Log; import android.view.SurfaceHolder; + import org.antennapod.audio.MediaPlayer; import de.danoeh.antennapod.core.preferences.UserPreferences; @@ -12,8 +15,17 @@ public class AudioPlayer extends MediaPlayer implements IPlayer { public AudioPlayer(Context context) { super(context); + PreferenceManager.getDefaultSharedPreferences(context) + .registerOnSharedPreferenceChangeListener(sonicListener); } + private final SharedPreferences.OnSharedPreferenceChangeListener sonicListener = + (sharedPreferences, key) -> { + if (key.equals(UserPreferences.PREF_SONIC)) { + checkMpi(); + } + }; + @Override public void setScreenOnWhilePlaying(boolean screenOn) { Log.e(TAG, "Setting screen on while playing not supported in Audio Player"); diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java index 0ad286093..1409ffe09 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java @@ -336,6 +336,8 @@ public abstract class PlaybackController { case PlaybackService.NOTIFICATION_TYPE_PLAYBACK_SPEED_CHANGE: onPlaybackSpeedChange(); break; + case PlaybackService.NOTIFICATION_TYPE_SET_SPEED_ABILITY_CHANGED: + onSetSpeedAbilityChanged(); } } @@ -362,6 +364,8 @@ public abstract class PlaybackController { public void onPlaybackSpeedChange() {} + public void onSetSpeedAbilityChanged() {} + public void onShutdownNotification() {} /** |