Fixed playback speed and pitch issues
This commit is contained in:
parent
e8f931f213
commit
111546bc4c
5 changed files with 21 additions and 30 deletions
|
@ -31,7 +31,7 @@ import java.lang.ref.WeakReference
|
|||
* Created by Beesham Sarendranauth (Beesham)
|
||||
*/
|
||||
class AutoMusicProvider(
|
||||
val mContext: Context,
|
||||
private val mContext: Context,
|
||||
private val songsRepository: SongRepository,
|
||||
private val albumsRepository: AlbumRepository,
|
||||
private val artistsRepository: ArtistRepository,
|
||||
|
|
|
@ -7,6 +7,7 @@ import android.content.IntentFilter
|
|||
import android.media.AudioAttributes
|
||||
import android.media.AudioManager
|
||||
import android.media.MediaPlayer
|
||||
import android.media.PlaybackParams
|
||||
import androidx.annotation.CallSuper
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.net.toUri
|
||||
|
@ -17,6 +18,8 @@ import code.name.monkey.retromusic.R
|
|||
import code.name.monkey.retromusic.extensions.showToast
|
||||
import code.name.monkey.retromusic.service.playback.Playback
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil.isAudioFocusEnabled
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil.playbackPitch
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil.playbackSpeed
|
||||
|
||||
abstract class LocalPlayback(val context: Context) : Playback, MediaPlayer.OnErrorListener,
|
||||
MediaPlayer.OnCompletionListener {
|
||||
|
@ -121,11 +124,14 @@ abstract class LocalPlayback(val context: Context) : Playback, MediaPlayer.OnErr
|
|||
} else {
|
||||
player.setDataSource(path)
|
||||
}
|
||||
player.setAudioAttributes(AudioAttributes.Builder()
|
||||
player.setAudioAttributes(
|
||||
AudioAttributes.Builder()
|
||||
.setUsage(AudioAttributes.USAGE_MEDIA)
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
|
||||
.build()
|
||||
)
|
||||
player.playbackParams = PlaybackParams().setSpeed(playbackSpeed).setPitch(playbackPitch)
|
||||
|
||||
player.setOnPreparedListener {
|
||||
player.setOnPreparedListener(null)
|
||||
completion(true)
|
||||
|
|
|
@ -23,6 +23,7 @@ import code.name.monkey.retromusic.extensions.uri
|
|||
import code.name.monkey.retromusic.model.Song
|
||||
import code.name.monkey.retromusic.service.playback.Playback.PlaybackCallbacks
|
||||
import code.name.monkey.retromusic.util.PreferenceUtil.isGapLessPlayback
|
||||
import code.name.monkey.retromusic.util.logE
|
||||
|
||||
/**
|
||||
* @author Andrew Neal, Karim Abou Zeid (kabouzeid)
|
||||
|
@ -141,10 +142,8 @@ class MultiPlayer(context: Context) : LocalPlayback(context) {
|
|||
override fun release() {
|
||||
stop()
|
||||
mCurrentMediaPlayer.release()
|
||||
if (mNextMediaPlayer != null) {
|
||||
mNextMediaPlayer?.release()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pauses playback. Call start() to resume.
|
||||
|
@ -249,7 +248,7 @@ class MultiPlayer(context: Context) : LocalPlayback(context) {
|
|||
mCurrentMediaPlayer = MediaPlayer()
|
||||
mCurrentMediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK)
|
||||
context.showToast(R.string.unplayable_file)
|
||||
Log.e(TAG, what.toString() + extra)
|
||||
logE(what.toString() + extra)
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -260,9 +259,9 @@ class MultiPlayer(context: Context) : LocalPlayback(context) {
|
|||
mCurrentMediaPlayer = mNextMediaPlayer!!
|
||||
isInitialized = true
|
||||
mNextMediaPlayer = null
|
||||
if (callbacks != null) callbacks?.onTrackWentToNext()
|
||||
callbacks?.onTrackWentToNext()
|
||||
} else {
|
||||
if (callbacks != null) callbacks?.onTrackEnded()
|
||||
callbacks?.onTrackEnded()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,6 +269,7 @@ class MultiPlayer(context: Context) : LocalPlayback(context) {
|
|||
|
||||
override fun setPlaybackSpeedPitch(speed: Float, pitch: Float) {
|
||||
mCurrentMediaPlayer.setPlaybackSpeedPitch(speed, pitch)
|
||||
mNextMediaPlayer?.setPlaybackSpeedPitch(speed, pitch)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -591,16 +591,9 @@ class MusicService : MediaBrowserServiceCompat(),
|
|||
* By default return the browsable root. Treat the EXTRA_RECENT flag as a special case
|
||||
* and return the recent root instead.
|
||||
*/
|
||||
var isRecentRequest = false
|
||||
if (rootHints != null) {
|
||||
isRecentRequest =
|
||||
rootHints.getBoolean(BrowserRoot.EXTRA_RECENT)
|
||||
}
|
||||
val browserRootPath = if (isRecentRequest) {
|
||||
AutoMediaIDHelper.RECENT_ROOT
|
||||
} else {
|
||||
AutoMediaIDHelper.MEDIA_ID_ROOT
|
||||
}
|
||||
val isRecentRequest = rootHints?.getBoolean(BrowserRoot.EXTRA_RECENT) ?: false
|
||||
val browserRootPath =
|
||||
if (isRecentRequest) AutoMediaIDHelper.RECENT_ROOT else AutoMediaIDHelper.MEDIA_ID_ROOT
|
||||
BrowserRoot(browserRootPath, null)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,6 @@ 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
|
||||
|
||||
|
||||
class PlaybackManager(val context: Context) {
|
||||
|
@ -35,9 +33,6 @@ 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()
|
||||
}
|
||||
|
@ -61,9 +56,6 @@ class PlaybackManager(val context: Context) {
|
|||
AudioFader.startFadeAnimator(playback!!, true)
|
||||
}
|
||||
}
|
||||
if (shouldSetSpeed) {
|
||||
playback?.setPlaybackSpeedPitch(playbackSpeed, playbackPitch)
|
||||
}
|
||||
playback?.start()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue