Fixed auto-next behavior and flashes when updating album art in the main

UI on old/slow devices.
This commit is contained in:
casey langen 2017-05-19 10:27:48 -07:00
parent a67e05dcd2
commit 9cf6cffef5
4 changed files with 31 additions and 16 deletions

View File

@ -43,7 +43,7 @@ namespace defaults {
static const std::string password = "";
static const int transcoder_cache_count = 50;
static const bool transcoder_synchronous = false;
static const bool transcoder_synchronous_fallback = true;
static const bool transcoder_synchronous_fallback = false;
}
namespace prefs {

View File

@ -58,22 +58,26 @@ public class MainActivity extends WebSocketActivityBase {
private WebSocketService wss = null;
private SharedPreferences prefs;
private PlaybackService playback;
private Handler handler = new Handler();
private TextView title, artist, album, playPause, volume;
private TextView titleWithArt, artistAndAlbumWithArt, volumeWithArt;
private View mainTrackMetadataWithAlbumArt, mainTrackMetadataNoAlbumArt;
private TextView notPlayingOrDisconnected;
private View buffering, bufferingWithArt;
private View connected;
private CheckBox shuffleCb, muteCb, repeatCb;
private View disconnectedOverlay;
private Handler handler = new Handler();
private PlaybackService playback;
private ImageView albumArtImageView;
private ViewPropertyAnimator metadataAnim1, metadataAnim2;
/* ugh, artwork related */
private enum DisplayMode { Artwork, NoArtwork, Stopped }
private View mainTrackMetadataWithAlbumArt, mainTrackMetadataNoAlbumArt;
private ViewPropertyAnimator metadataAnim1, metadataAnim2;
private AlbumArtModel albumArtModel = AlbumArtModel.empty();
private ImageView albumArtImageView;
private DisplayMode lastDisplayMode = DisplayMode.Stopped;
private String lastArtworkUrl = null;
static {
REPEAT_TO_STRING_ID = new HashMap<>();
@ -338,7 +342,7 @@ public class MainActivity extends WebSocketActivityBase {
this.playPause.setText(playing ? R.string.button_pause : R.string.button_play);
final boolean stopped = (playback.getPlaybackState() == PlaybackState.Stopped);
notPlayingOrDisconnected.setVisibility(stopped ? View.VISIBLE : View.GONE);
notPlayingOrDisconnected.setVisibility(!connected || stopped ? View.VISIBLE : View.GONE);
boolean buffering = playback.getPlaybackState() == PlaybackState.Buffering;
@ -413,6 +417,8 @@ public class MainActivity extends WebSocketActivityBase {
}
private void setMetadataDisplayMode(DisplayMode mode) {
lastDisplayMode = mode;
if (metadataAnim1 != null) {
metadataAnim1.cancel();
metadataAnim2.cancel();
@ -467,11 +473,13 @@ public class MainActivity extends WebSocketActivityBase {
final String url = albumArtModel.getUrl();
if (Strings.empty(url)) {
this.lastArtworkUrl = null;
albumArtModel.fetch();
setMetadataDisplayMode(DisplayMode.NoArtwork);
}
else {
else if (!url.equals(lastArtworkUrl) || lastDisplayMode == DisplayMode.Stopped) {
final int loadId = albumArtModel.getId();
this.lastArtworkUrl = url;
Glide.with(this)
.load(url)
@ -484,6 +492,7 @@ public class MainActivity extends WebSocketActivityBase {
boolean isFirstResource)
{
setMetadataDisplayMode(DisplayMode.NoArtwork);
lastArtworkUrl = null;
return false;
}
@ -511,6 +520,9 @@ public class MainActivity extends WebSocketActivityBase {
})
.into(albumArtImageView);
}
else {
setMetadataDisplayMode(lastDisplayMode);
}
}
private void navigateToCurrentArtist() {

View File

@ -211,15 +211,17 @@ public class ExoPlayerWrapper extends PlayerWrapper {
public void dispose() {
Preconditions.throwIfNotOnMainThread();
setState(State.Killing);
removeActivePlayer(this);
if (this.player != null) {
this.player.setPlayWhenReady(false);
this.player.removeListener(eventListener);
this.player.stop();
this.player.release();
if (!dead()) {
setState(State.Killing);
removeActivePlayer(this);
if (this.player != null) {
this.player.setPlayWhenReady(false);
this.player.removeListener(eventListener);
this.player.stop();
this.player.release();
}
setState(State.Disposed);
}
setState(State.Disposed);
}
@Override

View File

@ -90,6 +90,7 @@ public class StreamingPlaybackService implements PlaybackService {
if (nextMetadata != null && nextPlayer != null) {
if (currentPlayer != null) {
currentPlayer.setOnStateChangedListener(null);
currentPlayer.dispose();
}