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 /app/src/main/java | |
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
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/MediaplayerActivity.java | 76 |
1 files changed, 48 insertions, 28 deletions
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) { |