Code Cleanup crossfade
This commit is contained in:
parent
335d9000bf
commit
13573882a1
5 changed files with 17 additions and 6 deletions
|
@ -147,7 +147,7 @@ class MainActivity : AbsCastActivity(), OnSharedPreferenceChangeListener {
|
|||
}
|
||||
|
||||
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
|
||||
if (key == GENERAL_THEME || key == BLACK_THEME || key == ADAPTIVE_COLOR_APP || key == USER_NAME || key == TOGGLE_FULL_SCREEN || key == TOGGLE_VOLUME || key == ROUND_CORNERS || key == CAROUSEL_EFFECT || key == NOW_PLAYING_SCREEN_ID || key == TOGGLE_GENRE || key == BANNER_IMAGE_PATH || key == PROFILE_IMAGE_PATH || key == CIRCULAR_ALBUM_ART || key == KEEP_SCREEN_ON || key == TOGGLE_SEPARATE_LINE || key == TOGGLE_HOME_BANNER || key == TOGGLE_ADD_CONTROLS || key == ALBUM_COVER_STYLE || key == HOME_ARTIST_GRID_STYLE || key == ALBUM_COVER_TRANSFORM || key == DESATURATED_COLOR || key == EXTRA_SONG_INFO || key == TAB_TEXT_MODE || key == LANGUAGE_NAME || key == LIBRARY_CATEGORIES) {
|
||||
if (key == GENERAL_THEME || key == MATERIAL_YOU || key == BLACK_THEME || key == ADAPTIVE_COLOR_APP || key == USER_NAME || key == TOGGLE_FULL_SCREEN || key == TOGGLE_VOLUME || key == ROUND_CORNERS || key == CAROUSEL_EFFECT || key == NOW_PLAYING_SCREEN_ID || key == TOGGLE_GENRE || key == BANNER_IMAGE_PATH || key == PROFILE_IMAGE_PATH || key == CIRCULAR_ALBUM_ART || key == KEEP_SCREEN_ON || key == TOGGLE_SEPARATE_LINE || key == TOGGLE_HOME_BANNER || key == TOGGLE_ADD_CONTROLS || key == ALBUM_COVER_STYLE || key == HOME_ARTIST_GRID_STYLE || key == ALBUM_COVER_TRANSFORM || key == DESATURATED_COLOR || key == EXTRA_SONG_INFO || key == TAB_TEXT_MODE || key == LANGUAGE_NAME || key == LIBRARY_CATEGORIES) {
|
||||
postRecreate()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
|||
private var fadeInAnimator: Animator? = null
|
||||
private var fadeOutAnimator: Animator? = null
|
||||
private var callbacks: PlaybackCallbacks? = null
|
||||
private var crossFadeDuration = PreferenceUtil.crossFadeDuration
|
||||
|
||||
init {
|
||||
player1.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK)
|
||||
|
@ -120,7 +121,7 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
|||
|
||||
// This has to run when queue is changed or song is changed manually by user
|
||||
fun sourceChangedByUser() {
|
||||
this.hasDataSource = false
|
||||
hasDataSource = false
|
||||
cancelFade()
|
||||
getCurrentPlayer()?.apply {
|
||||
if (isPlaying) stop()
|
||||
|
@ -304,7 +305,7 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
|||
NOT_SET
|
||||
}
|
||||
|
||||
inner class DurationListener : CoroutineScope by CrossFadeScope() {
|
||||
inner class DurationListener : CoroutineScope by crossFadeScope() {
|
||||
|
||||
private var job: Job? = null
|
||||
|
||||
|
@ -325,9 +326,8 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
|||
|
||||
|
||||
fun onDurationUpdated(progress: Int, total: Int) {
|
||||
if (total > 0 && (total - progress).div(1000) == PreferenceUtil.crossFadeDuration) {
|
||||
if (total > 0 && (total - progress).div(1000) == crossFadeDuration) {
|
||||
getNextPlayer()?.let { player ->
|
||||
durationListener.stop()
|
||||
val nextSong = MusicPlayerRemote.nextSong
|
||||
if (nextSong != null) {
|
||||
setDataSourceImpl(player, MusicUtil.getSongFileUri(nextSong.id).toString())
|
||||
|
@ -350,6 +350,10 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
|||
}
|
||||
callbacks?.onTrackEndedWithCrossfade()
|
||||
}
|
||||
|
||||
override fun setCrossFadeDuration(duration: Int) {
|
||||
crossFadeDuration = duration
|
||||
}
|
||||
}
|
||||
|
||||
internal fun CrossFadeScope(): CoroutineScope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
internal fun crossFadeScope(): CoroutineScope = CoroutineScope(Job() + Dispatchers.Main)
|
|
@ -322,4 +322,7 @@ public class MultiPlayer
|
|||
if (callbacks != null) callbacks.onTrackEnded();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCrossFadeDuration(int duration) { }
|
||||
}
|
|
@ -882,6 +882,8 @@ public class MusicService extends MediaBrowserServiceCompat
|
|||
boolean wasPlaying = isPlaying();
|
||||
/* Switch to MultiPlayer if Crossfade duration is 0 and
|
||||
Playback is not an instance of MultiPlayer */
|
||||
if (playback != null)
|
||||
playback.setCrossFadeDuration(PreferenceUtil.INSTANCE.getCrossFadeDuration());
|
||||
if (!(playback instanceof MultiPlayer) && PreferenceUtil.INSTANCE.getCrossFadeDuration() == 0) {
|
||||
if (playback != null) {
|
||||
playback.release();
|
||||
|
|
|
@ -47,6 +47,8 @@ interface Playback {
|
|||
|
||||
fun setAudioSessionId(sessionId: Int): Boolean
|
||||
|
||||
fun setCrossFadeDuration(duration: Int)
|
||||
|
||||
interface PlaybackCallbacks {
|
||||
fun onTrackWentToNext()
|
||||
|
||||
|
|
Loading…
Reference in a new issue