Skip to content

Commit

Permalink
feat: option to auto load more songs, close #1468
Browse files Browse the repository at this point in the history
  • Loading branch information
z-huang committed Aug 31, 2024
1 parent 0b6d954 commit 00a5094
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ enum class AudioQuality {
val PersistentQueueKey = booleanPreferencesKey("persistentQueue")
val SkipSilenceKey = booleanPreferencesKey("skipSilence")
val AudioNormalizationKey = booleanPreferencesKey("audioNormalization")
val AutoLoadMoreKey = booleanPreferencesKey("autoLoadMore")
val AutoSkipNextOnErrorKey = booleanPreferencesKey("autoSkipNextOnError")
val StopMusicOnTaskClearKey = booleanPreferencesKey("stopMusicOnTaskClear")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import com.zionhuang.music.R
import com.zionhuang.music.constants.AudioNormalizationKey
import com.zionhuang.music.constants.AudioQuality
import com.zionhuang.music.constants.AudioQualityKey
import com.zionhuang.music.constants.AutoLoadMoreKey
import com.zionhuang.music.constants.AutoSkipNextOnErrorKey
import com.zionhuang.music.constants.DiscordTokenKey
import com.zionhuang.music.constants.EnableDiscordRPCKey
Expand Down Expand Up @@ -527,7 +528,8 @@ class MusicService : MediaLibraryService(),

override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
// Auto load more songs
if (reason != Player.MEDIA_ITEM_TRANSITION_REASON_REPEAT &&
if (dataStore.get(AutoLoadMoreKey, true) &&
reason != Player.MEDIA_ITEM_TRANSITION_REASON_REPEAT &&
player.playbackState != STATE_IDLE &&
player.mediaItemCount - player.currentMediaItemIndex <= 5 &&
currentQueue.hasNextPage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.zionhuang.music.R
import com.zionhuang.music.constants.AudioNormalizationKey
import com.zionhuang.music.constants.AudioQuality
import com.zionhuang.music.constants.AudioQualityKey
import com.zionhuang.music.constants.AutoLoadMoreKey
import com.zionhuang.music.constants.AutoSkipNextOnErrorKey
import com.zionhuang.music.constants.PersistentQueueKey
import com.zionhuang.music.constants.SkipSilenceKey
Expand All @@ -44,6 +45,7 @@ fun PlayerSettings(
val (persistentQueue, onPersistentQueueChange) = rememberPreference(PersistentQueueKey, defaultValue = true)
val (skipSilence, onSkipSilenceChange) = rememberPreference(SkipSilenceKey, defaultValue = false)
val (audioNormalization, onAudioNormalizationChange) = rememberPreference(AudioNormalizationKey, defaultValue = true)
val (autoLoadMore, onAutoLoadMoreChange) = rememberPreference(AutoLoadMoreKey, defaultValue = true)
val (autoSkipNextOnError, onAutoSkipNextOnErrorChange) = rememberPreference(AutoSkipNextOnErrorKey, defaultValue = false)
val (stopMusicOnTaskClear, onStopMusicOnTaskClearChange) = rememberPreference(StopMusicOnTaskClearKey, defaultValue = false)

Expand Down Expand Up @@ -98,6 +100,14 @@ fun PlayerSettings(
onCheckedChange = onPersistentQueueChange
)

SwitchPreference(
title = { Text(stringResource(R.string.auto_load_more)) },
description = stringResource(R.string.auto_load_more_desc),
icon = { Icon(painterResource(R.drawable.playlist_add), null) },
checked = autoLoadMore,
onCheckedChange = onAutoLoadMoreChange
)

SwitchPreference(
title = { Text(stringResource(R.string.auto_skip_next_on_error)) },
description = stringResource(R.string.auto_skip_next_on_error_desc),
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@
<string name="queue">播放佇列</string>
<string name="persistent_queue">保留播放佇列</string>
<string name="persistent_queue_desc">開啟應用程式時還原上次的播放佇列</string>
<string name="auto_load_more">自動載入更多歌曲</string>
<string name="auto_load_more_desc">當播放佇列快結束時,自動加入更多歌曲,如果可以的話</string>
<string name="skip_silence">跳過無聲片段</string>
<string name="audio_normalization">標準化音量</string>
<string name="auto_skip_next_on_error">發生錯誤時自動跳到下一首</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@
<string name="queue">Queue</string>
<string name="persistent_queue">Persistent queue</string>
<string name="persistent_queue_desc">Restore your last queue when the app starts</string>
<string name="auto_load_more">Auto load more songs</string>
<string name="auto_load_more_desc">Automatically add more songs when the end of the queue is reached, if possible</string>
<string name="skip_silence">Skip silence</string>
<string name="audio_normalization">Audio normalization</string>
<string name="auto_skip_next_on_error">Auto skip to next song when error occurs</string>
Expand Down

0 comments on commit 00a5094

Please sign in to comment.