Correctly set playback speed and pitch
This commit is contained in:
parent
d6c4d5e133
commit
b9f0adc9c2
3 changed files with 8 additions and 11 deletions
|
@ -19,8 +19,6 @@ import code.name.monkey.retromusic.service.AudioFader.Companion.createFadeAnimat
|
|||
import code.name.monkey.retromusic.service.playback.Playback
|
||||
import code.name.monkey.retromusic.service.playback.Playback.PlaybackCallbacks
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil.playbackPitch
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil.playbackSpeed
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
/** @author Prathamesh M */
|
||||
|
@ -168,7 +166,6 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
|||
player.setAudioAttributes(
|
||||
AudioAttributes.Builder().setLegacyStreamType(AudioManager.STREAM_MUSIC).build()
|
||||
)
|
||||
player.setPlaybackSpeedPitch(playbackSpeed, playbackPitch)
|
||||
player.setOnPreparedListener {
|
||||
player.setOnPreparedListener(null)
|
||||
completion(true)
|
||||
|
@ -321,7 +318,6 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
fun onDurationUpdated(progress: Int, total: Int) {
|
||||
if (total > 0 && (total - progress).div(1000) == crossFadeDuration) {
|
||||
getNextPlayer()?.let { player ->
|
||||
|
@ -369,10 +365,6 @@ internal fun crossFadeScope(): CoroutineScope = CoroutineScope(Job() + Dispatche
|
|||
|
||||
fun MediaPlayer.setPlaybackSpeedPitch(speed: Float, pitch: Float) {
|
||||
if (hasMarshmallow()) {
|
||||
val wasPlaying: Boolean = isPlaying
|
||||
playbackParams = PlaybackParams().setSpeed(speed).setPitch(pitch)
|
||||
if (!wasPlaying) {
|
||||
if (isPlaying) pause()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -27,8 +27,6 @@ import code.name.monkey.retromusic.model.Song
|
|||
import code.name.monkey.retromusic.service.playback.Playback
|
||||
import code.name.monkey.retromusic.service.playback.Playback.PlaybackCallbacks
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil.isGapLessPlayback
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil.playbackPitch
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil.playbackSpeed
|
||||
|
||||
/**
|
||||
* @author Andrew Neal, Karim Abou Zeid (kabouzeid)
|
||||
|
@ -91,7 +89,6 @@ class MultiPlayer internal constructor(private val context: Context) : Playback,
|
|||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
|
||||
.build()
|
||||
)
|
||||
player.setPlaybackSpeedPitch(playbackSpeed, playbackPitch)
|
||||
player.setOnPreparedListener {
|
||||
player.setOnPreparedListener(null)
|
||||
completion(true)
|
||||
|
|
|
@ -6,6 +6,8 @@ import android.media.audiofx.AudioEffect
|
|||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.service.playback.Playback
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil.playbackPitch
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil.playbackSpeed
|
||||
import com.google.android.gms.cast.framework.CastSession
|
||||
|
||||
|
||||
|
@ -32,6 +34,9 @@ class PlaybackManager(val context: Context) {
|
|||
val isPlaying: Boolean
|
||||
get() = playback != null && playback!!.isPlaying
|
||||
|
||||
private val shouldSetSpeed: Boolean
|
||||
get() = !(playbackSpeed == 1f && playbackPitch == 1f)
|
||||
|
||||
init {
|
||||
playback = createLocalPlayback()
|
||||
}
|
||||
|
@ -52,6 +57,9 @@ class PlaybackManager(val context: Context) {
|
|||
onPlay()
|
||||
}
|
||||
}
|
||||
if (shouldSetSpeed) {
|
||||
playback?.setPlaybackSpeedPitch(playbackSpeed, playbackPitch)
|
||||
}
|
||||
playback?.start()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue