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?) {
|
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()
|
postRecreate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
||||||
private var fadeInAnimator: Animator? = null
|
private var fadeInAnimator: Animator? = null
|
||||||
private var fadeOutAnimator: Animator? = null
|
private var fadeOutAnimator: Animator? = null
|
||||||
private var callbacks: PlaybackCallbacks? = null
|
private var callbacks: PlaybackCallbacks? = null
|
||||||
|
private var crossFadeDuration = PreferenceUtil.crossFadeDuration
|
||||||
|
|
||||||
init {
|
init {
|
||||||
player1.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK)
|
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
|
// This has to run when queue is changed or song is changed manually by user
|
||||||
fun sourceChangedByUser() {
|
fun sourceChangedByUser() {
|
||||||
this.hasDataSource = false
|
hasDataSource = false
|
||||||
cancelFade()
|
cancelFade()
|
||||||
getCurrentPlayer()?.apply {
|
getCurrentPlayer()?.apply {
|
||||||
if (isPlaying) stop()
|
if (isPlaying) stop()
|
||||||
|
@ -304,7 +305,7 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
||||||
NOT_SET
|
NOT_SET
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class DurationListener : CoroutineScope by CrossFadeScope() {
|
inner class DurationListener : CoroutineScope by crossFadeScope() {
|
||||||
|
|
||||||
private var job: Job? = null
|
private var job: Job? = null
|
||||||
|
|
||||||
|
@ -325,9 +326,8 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
||||||
|
|
||||||
|
|
||||||
fun onDurationUpdated(progress: Int, total: Int) {
|
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 ->
|
getNextPlayer()?.let { player ->
|
||||||
durationListener.stop()
|
|
||||||
val nextSong = MusicPlayerRemote.nextSong
|
val nextSong = MusicPlayerRemote.nextSong
|
||||||
if (nextSong != null) {
|
if (nextSong != null) {
|
||||||
setDataSourceImpl(player, MusicUtil.getSongFileUri(nextSong.id).toString())
|
setDataSourceImpl(player, MusicUtil.getSongFileUri(nextSong.id).toString())
|
||||||
|
@ -350,6 +350,10 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
||||||
}
|
}
|
||||||
callbacks?.onTrackEndedWithCrossfade()
|
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();
|
if (callbacks != null) callbacks.onTrackEnded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setCrossFadeDuration(int duration) { }
|
||||||
}
|
}
|
|
@ -882,6 +882,8 @@ public class MusicService extends MediaBrowserServiceCompat
|
||||||
boolean wasPlaying = isPlaying();
|
boolean wasPlaying = isPlaying();
|
||||||
/* Switch to MultiPlayer if Crossfade duration is 0 and
|
/* Switch to MultiPlayer if Crossfade duration is 0 and
|
||||||
Playback is not an instance of MultiPlayer */
|
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 instanceof MultiPlayer) && PreferenceUtil.INSTANCE.getCrossFadeDuration() == 0) {
|
||||||
if (playback != null) {
|
if (playback != null) {
|
||||||
playback.release();
|
playback.release();
|
||||||
|
|
|
@ -47,6 +47,8 @@ interface Playback {
|
||||||
|
|
||||||
fun setAudioSessionId(sessionId: Int): Boolean
|
fun setAudioSessionId(sessionId: Int): Boolean
|
||||||
|
|
||||||
|
fun setCrossFadeDuration(duration: Int)
|
||||||
|
|
||||||
interface PlaybackCallbacks {
|
interface PlaybackCallbacks {
|
||||||
fun onTrackWentToNext()
|
fun onTrackWentToNext()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue