Merge pull request #616 from naveensingh/fix_shuffle_and_other_issues
Fix shuffle and other issues
This commit is contained in:
commit
021666c574
4 changed files with 39 additions and 19 deletions
|
@ -22,7 +22,7 @@ private const val SKIP_SILENCE_THRESHOLD_LEVEL = 16.toShort()
|
||||||
@UnstableApi
|
@UnstableApi
|
||||||
class AudioOnlyRenderersFactory(context: Context) : DefaultRenderersFactory(context) {
|
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(
|
val silenceSkippingAudioProcessor = SilenceSkippingAudioProcessor(
|
||||||
SKIP_SILENCE_MINIMUM_DURATION_US,
|
SKIP_SILENCE_MINIMUM_DURATION_US,
|
||||||
DEFAULT_PADDING_SILENCE_US,
|
DEFAULT_PADDING_SILENCE_US,
|
||||||
|
@ -32,6 +32,13 @@ class AudioOnlyRenderersFactory(context: Context) : DefaultRenderersFactory(cont
|
||||||
return DefaultAudioSink.Builder(context)
|
return DefaultAudioSink.Builder(context)
|
||||||
.setEnableFloatOutput(enableFloatOutput)
|
.setEnableFloatOutput(enableFloatOutput)
|
||||||
.setEnableAudioTrackPlaybackParams(enableAudioTrackPlaybackParams)
|
.setEnableAudioTrackPlaybackParams(enableAudioTrackPlaybackParams)
|
||||||
|
.setOffloadMode(
|
||||||
|
if (enableOffload) {
|
||||||
|
DefaultAudioSink.OFFLOAD_MODE_ENABLED_GAPLESS_REQUIRED
|
||||||
|
} else {
|
||||||
|
DefaultAudioSink.OFFLOAD_MODE_DISABLED
|
||||||
|
}
|
||||||
|
)
|
||||||
.setAudioProcessorChain(
|
.setAudioProcessorChain(
|
||||||
DefaultAudioSink.DefaultAudioProcessorChain(
|
DefaultAudioSink.DefaultAudioProcessorChain(
|
||||||
arrayOf(),
|
arrayOf(),
|
||||||
|
|
|
@ -64,7 +64,11 @@ private fun PlaybackService.initializePlayer(handleAudioFocus: Boolean, handleAu
|
||||||
.build(),
|
.build(),
|
||||||
handleAudioFocus
|
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)
|
.setSeekBackIncrementMs(SEEK_INTERVAL_MS)
|
||||||
.setSeekForwardIncrementMs(SEEK_INTERVAL_MS)
|
.setSeekForwardIncrementMs(SEEK_INTERVAL_MS)
|
||||||
.setLooper(playerThread.looper)
|
.setLooper(playerThread.looper)
|
||||||
|
|
|
@ -141,26 +141,35 @@ class SimpleMusicPlayer(private val exoPlayer: ExoPlayer) : ForwardingPlayer(exo
|
||||||
private fun seekWithDelay() {
|
private fun seekWithDelay() {
|
||||||
seekJob?.cancel()
|
seekJob?.cancel()
|
||||||
seekJob = scope.launch {
|
seekJob = scope.launch {
|
||||||
delay(timeMillis = 400)
|
delay(timeMillis = 300)
|
||||||
if (seekToNextCount > 0 || seekToPreviousCount > 0) {
|
val seekCount = seekToNextCount - seekToPreviousCount
|
||||||
runOnPlayerThread {
|
if (seekCount != 0) {
|
||||||
if (currentMediaItem != null) {
|
seekByCount(seekCount)
|
||||||
if (seekToNextCount > 0) {
|
|
||||||
seekTo(rotateIndex(currentMediaItemIndex + seekToNextCount), 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (seekToPreviousCount > 0) {
|
|
||||||
seekTo(rotateIndex(currentMediaItemIndex - seekToPreviousCount), 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
seekToNextCount = 0
|
|
||||||
seekToPreviousCount = 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 {
|
private fun rotateIndex(index: Int): Int {
|
||||||
val count = mediaItemCount
|
val count = mediaItemCount
|
||||||
return (index % count + count) % count
|
return (index % count + count) % count
|
||||||
|
|
|
@ -18,7 +18,7 @@ eventbus = "3.3.1"
|
||||||
lottie = "6.1.0"
|
lottie = "6.1.0"
|
||||||
m3uParser = "1.3.0"
|
m3uParser = "1.3.0"
|
||||||
media = "1.6.0"
|
media = "1.6.0"
|
||||||
media3 = "1.2.0-alpha02"
|
media3 = "1.1.1"
|
||||||
room = "2.5.2"
|
room = "2.5.2"
|
||||||
#Simple Mobile Tools
|
#Simple Mobile Tools
|
||||||
simple-commons = "6a7777d740"
|
simple-commons = "6a7777d740"
|
||||||
|
|
Loading…
Reference in a new issue