Skip to content

Commit

Permalink
Merge pull request #4510 from Abhinavreddy-B/resume-playback-on-start
Browse files Browse the repository at this point in the history
Implemented autoplay option on opening the app
  • Loading branch information
fast4x authored Nov 13, 2024
2 parents 6b824a5 + abe7fa6 commit abebb7a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ import it.fast4x.rimusic.utils.playbackFadeAudioDurationKey
import it.fast4x.rimusic.utils.preferences
import it.fast4x.rimusic.utils.putEnum
import it.fast4x.rimusic.utils.queueLoopTypeKey
import it.fast4x.rimusic.utils.resumePlaybackOnStartKey
import it.fast4x.rimusic.utils.resumePlaybackWhenDeviceConnectedKey
import it.fast4x.rimusic.utils.setLikeState
import it.fast4x.rimusic.utils.showDownloadButtonBackgroundPlayerKey
Expand Down Expand Up @@ -437,6 +438,7 @@ class PlayerServiceModern : MediaLibraryService(),
// Load persistent queue when start activity and save periodically in background
if (isPersistentQueueEnabled) {
maybeRestorePlayerQueue()
maybeResumePlaybackOnStart()

val scheduler = Executors.newScheduledThreadPool(1)
scheduler.scheduleWithFixedDelay({
Expand Down Expand Up @@ -1306,6 +1308,13 @@ class PlayerServiceModern : MediaLibraryService(),
}
}

private fun maybeResumePlaybackOnStart() {
if(!isPersistentQueueEnabled || !preferences.getBoolean(resumePlaybackOnStartKey, false)) return

if(!player.isPlaying) {
player.play()
}
}

@ExperimentalCoroutinesApi
@FlowPreview
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ import it.fast4x.rimusic.utils.queueTypeKey
import it.fast4x.rimusic.utils.recommendationsNumberKey
import it.fast4x.rimusic.utils.rememberEqualizerLauncher
import it.fast4x.rimusic.utils.rememberPreference
import it.fast4x.rimusic.utils.resumePlaybackOnStartKey
import it.fast4x.rimusic.utils.resumePlaybackWhenDeviceConnectedKey
import it.fast4x.rimusic.utils.shakeEventEnabledKey
import it.fast4x.rimusic.utils.showButtonPlayerAddToPlaylistKey
Expand Down Expand Up @@ -220,6 +221,8 @@ fun DefaultUiSettings() {
exoPlayerMinTimeForEvent = ExoPlayerMinTimeForEvent.`20s`
var persistentQueue by rememberPreference(persistentQueueKey, false)
persistentQueue = false
var resumePlaybackOnStart by rememberPreference(resumePlaybackOnStartKey, false)
resumePlaybackOnStart = false
var closebackgroundPlayer by rememberPreference(closebackgroundPlayerKey, false)
closebackgroundPlayer = false
var closeWithBackButton by rememberPreference(closeWithBackButtonKey, true)
Expand Down Expand Up @@ -530,6 +533,7 @@ fun UiSettings(
ExoPlayerMinTimeForEvent.`20s`
)
var persistentQueue by rememberPreference(persistentQueueKey, false)
var resumePlaybackOnStart by rememberPreference(resumePlaybackOnStartKey, false)
var closebackgroundPlayer by rememberPreference(closebackgroundPlayerKey, false)
var closeWithBackButton by rememberPreference(closeWithBackButtonKey, true)
var resumePlaybackWhenDeviceConnected by rememberPreference(
Expand Down Expand Up @@ -1075,6 +1079,23 @@ fun UiSettings(
}
)
RestartPlayerService(restartService, onRestart = { restartService = false })

AnimatedVisibility(visible = persistentQueue) {
Column(
modifier = Modifier.padding(start = 25.dp)
) {
SwitchSettingEntry(
title = stringResource(R.string.resume_playback_on_start),
text = stringResource(R.string.resume_automatically_when_app_opens),
isChecked = resumePlaybackOnStart,
onCheckedChange = {
resumePlaybackOnStart = it
restartService = true
}
)
RestartPlayerService(restartService, onRestart = { restartService = false } )
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const val skipMediaOnErrorKey = "skipMediaOnError"
const val volumeNormalizationKey = "volumeNormalization"
const val resumePlaybackWhenDeviceConnectedKey = "resumePlaybackWhenDeviceConnected"
const val persistentQueueKey = "persistentQueue"
const val resumePlaybackOnStartKey = "resumePlaybackOnStart"
const val closebackgroundPlayerKey = "closebackgroundPlayer"
const val closeWithBackButtonKey = "closeWithBackButton"
const val isShowingSynchronizedLyricsKey = "isShowingSynchronizedLyrics"
Expand Down
2 changes: 2 additions & 0 deletions composeApp/src/androidMain/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -778,4 +778,6 @@
<string name="failed_to_remove_thumbnail">Failed to Remove Thumbnail</string>
<string name="showsecondline">Show Translation in the Second Line</string>
<string name="enter_the_value">Enter The Value</string>
<string name="resume_playback_on_start">Resume Playback On Start</string>
<string name="resume_automatically_when_app_opens">Resume Playback automatically when the app is opened</string>
</resources>

0 comments on commit abebb7a

Please sign in to comment.