Merge pull request #616 from naveensingh/fix_shuffle_and_other_issues

Fix shuffle and other issues
This commit is contained in:
Tibor Kaputa 2023-10-17 08:32:05 +02:00 committed by GitHub
commit 021666c574
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 19 deletions

View file

@ -22,7 +22,7 @@ private const val SKIP_SILENCE_THRESHOLD_LEVEL = 16.toShort()
@UnstableApi
class AudioOnlyRenderersFactory(context: Context) : DefaultRenderersFactory(context) {
override fun buildAudioSink(context: Context, enableFloatOutput: Boolean, enableAudioTrackPlaybackParams: Boolean): AudioSink {
override fun buildAudioSink(context: Context, enableFloatOutput: Boolean, enableAudioTrackPlaybackParams: Boolean, enableOffload: Boolean): AudioSink? {
val silenceSkippingAudioProcessor = SilenceSkippingAudioProcessor(
SKIP_SILENCE_MINIMUM_DURATION_US,
DEFAULT_PADDING_SILENCE_US,
@ -32,6 +32,13 @@ class AudioOnlyRenderersFactory(context: Context) : DefaultRenderersFactory(cont
return DefaultAudioSink.Builder(context)
.setEnableFloatOutput(enableFloatOutput)
.setEnableAudioTrackPlaybackParams(enableAudioTrackPlaybackParams)
.setOffloadMode(
if (enableOffload) {
DefaultAudioSink.OFFLOAD_MODE_ENABLED_GAPLESS_REQUIRED
} else {
DefaultAudioSink.OFFLOAD_MODE_DISABLED
}
)
.setAudioProcessorChain(
DefaultAudioSink.DefaultAudioProcessorChain(
arrayOf(),

View file

@ -64,7 +64,11 @@ private fun PlaybackService.initializePlayer(handleAudioFocus: Boolean, handleAu
.build(),
handleAudioFocus
)
.setSkipSilenceEnabled(skipSilence)
.setSkipSilenceEnabled(
// TODO: Enable when https://github.com/androidx/media/issues/712 is resolved.
// See https://github.com/SimpleMobileTools/Simple-Music-Player/issues/604
false //skipSilence
)
.setSeekBackIncrementMs(SEEK_INTERVAL_MS)
.setSeekForwardIncrementMs(SEEK_INTERVAL_MS)
.setLooper(playerThread.looper)

View file

@ -141,26 +141,35 @@ class SimpleMusicPlayer(private val exoPlayer: ExoPlayer) : ForwardingPlayer(exo
private fun seekWithDelay() {
seekJob?.cancel()
seekJob = scope.launch {
delay(timeMillis = 400)
if (seekToNextCount > 0 || seekToPreviousCount > 0) {
runOnPlayerThread {
if (currentMediaItem != null) {
if (seekToNextCount > 0) {
seekTo(rotateIndex(currentMediaItemIndex + seekToNextCount), 0)
}
if (seekToPreviousCount > 0) {
seekTo(rotateIndex(currentMediaItemIndex - seekToPreviousCount), 0)
}
seekToNextCount = 0
seekToPreviousCount = 0
}
}
delay(timeMillis = 300)
val seekCount = seekToNextCount - seekToPreviousCount
if (seekCount != 0) {
seekByCount(seekCount)
}
}
}
private fun seekByCount(seekCount: Int) {
runOnPlayerThread {
if (currentMediaItem == null) {
return@runOnPlayerThread
}
val currentIndex = currentMediaItemIndex
val seekIndex = if (shuffleModeEnabled) {
val shuffledIndex = shuffledMediaItemsIndices.indexOf(currentIndex)
val seekIndex = rotateIndex(shuffledIndex + seekCount)
shuffledMediaItemsIndices.getOrNull(seekIndex) ?: return@runOnPlayerThread
} else {
rotateIndex(currentIndex + seekCount)
}
seekTo(seekIndex, 0)
seekToNextCount = 0
seekToPreviousCount = 0
}
}
private fun rotateIndex(index: Int): Int {
val count = mediaItemCount
return (index % count + count) % count

View file

@ -18,7 +18,7 @@ eventbus = "3.3.1"
lottie = "6.1.0"
m3uParser = "1.3.0"
media = "1.6.0"
media3 = "1.2.0-alpha02"
media3 = "1.1.1"
room = "2.5.2"
#Simple Mobile Tools
simple-commons = "6a7777d740"