Fix Audio Crossfade
This commit is contained in:
parent
608c265390
commit
806b3beaa7
4 changed files with 15 additions and 25 deletions
|
@ -120,20 +120,9 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
||||||
override val isPlaying: Boolean
|
override val isPlaying: Boolean
|
||||||
get() = mIsInitialized && getCurrentPlayer()?.isPlaying == true
|
get() = mIsInitialized && getCurrentPlayer()?.isPlaying == true
|
||||||
|
|
||||||
// This has to run when queue is changed or song is changed manually by user
|
override fun setDataSource(path: String, force: Boolean): Boolean {
|
||||||
fun sourceChangedByUser() {
|
|
||||||
hasDataSource = false
|
|
||||||
cancelFade()
|
|
||||||
getCurrentPlayer()?.apply {
|
|
||||||
if (isPlaying) stop()
|
|
||||||
}
|
|
||||||
getNextPlayer()?.apply {
|
|
||||||
if (isPlaying) stop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setDataSource(path: String): Boolean {
|
|
||||||
cancelFade()
|
cancelFade()
|
||||||
|
if (force) hasDataSource = false
|
||||||
mIsInitialized = false
|
mIsInitialized = false
|
||||||
/* We've already set DataSource if initialized is true in setNextDataSource */
|
/* We've already set DataSource if initialized is true in setNextDataSource */
|
||||||
if (!hasDataSource) {
|
if (!hasDataSource) {
|
||||||
|
@ -154,7 +143,7 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
||||||
*/
|
*/
|
||||||
private fun setDataSourceImpl(
|
private fun setDataSourceImpl(
|
||||||
player: MediaPlayer,
|
player: MediaPlayer,
|
||||||
path: String
|
path: String,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
player.reset()
|
player.reset()
|
||||||
player.setOnPreparedListener(null)
|
player.setOnPreparedListener(null)
|
||||||
|
|
|
@ -30,6 +30,8 @@ import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import code.name.monkey.appthemehelper.util.VersionUtils;
|
import code.name.monkey.appthemehelper.util.VersionUtils;
|
||||||
import code.name.monkey.retromusic.ConstantsKt;
|
import code.name.monkey.retromusic.ConstantsKt;
|
||||||
import code.name.monkey.retromusic.R;
|
import code.name.monkey.retromusic.R;
|
||||||
|
@ -66,7 +68,7 @@ public class MultiPlayer
|
||||||
* @return True if the <code>player</code> has been prepared and is ready to play, false otherwise
|
* @return True if the <code>player</code> has been prepared and is ready to play, false otherwise
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean setDataSource(@NonNull final String path) {
|
public boolean setDataSource(@NotNull final String path, boolean force) {
|
||||||
mIsInitialized = false;
|
mIsInitialized = false;
|
||||||
mIsInitialized = setDataSourceImpl(mCurrentMediaPlayer, path);
|
mIsInitialized = setDataSourceImpl(mCurrentMediaPlayer, path);
|
||||||
if (mIsInitialized) {
|
if (mIsInitialized) {
|
||||||
|
|
|
@ -92,6 +92,7 @@ import code.name.monkey.retromusic.util.PreferenceUtil.unregisterOnSharedPrefere
|
||||||
import code.name.monkey.retromusic.volume.AudioVolumeObserver
|
import code.name.monkey.retromusic.volume.AudioVolumeObserver
|
||||||
import code.name.monkey.retromusic.volume.OnAudioVolumeChangedListener
|
import code.name.monkey.retromusic.volume.OnAudioVolumeChangedListener
|
||||||
import com.bumptech.glide.request.target.CustomTarget
|
import com.bumptech.glide.request.target.CustomTarget
|
||||||
|
import com.bumptech.glide.request.target.Target
|
||||||
import com.bumptech.glide.request.transition.Transition
|
import com.bumptech.glide.request.transition.Transition
|
||||||
import org.koin.java.KoinJavaComponent.get
|
import org.koin.java.KoinJavaComponent.get
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -910,14 +911,6 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
}
|
}
|
||||||
|
|
||||||
fun playSongAtImpl(position: Int) {
|
fun playSongAtImpl(position: Int) {
|
||||||
if (!trackEndedByCrossfade) {
|
|
||||||
// This is only imp if we are using crossfade
|
|
||||||
if (playback is CrossFadePlayer) {
|
|
||||||
(playback as CrossFadePlayer).sourceChangedByUser()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
trackEndedByCrossfade = false
|
|
||||||
}
|
|
||||||
if (openTrackAndPrepareNextAt(position)) {
|
if (openTrackAndPrepareNextAt(position)) {
|
||||||
play()
|
play()
|
||||||
} else {
|
} else {
|
||||||
|
@ -1285,9 +1278,15 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun openCurrent(): Boolean {
|
private fun openCurrent(): Boolean {
|
||||||
|
val force = if (!trackEndedByCrossfade) {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
trackEndedByCrossfade = false
|
||||||
|
false
|
||||||
|
}
|
||||||
return try {
|
return try {
|
||||||
if (playback != null) {
|
if (playback != null) {
|
||||||
return playback!!.setDataSource(getTrackUri(currentSong))
|
return playback!!.setDataSource(getTrackUri(currentSong), force)
|
||||||
} else false
|
} else false
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
|
|
@ -23,7 +23,7 @@ interface Playback {
|
||||||
|
|
||||||
val audioSessionId: Int
|
val audioSessionId: Int
|
||||||
|
|
||||||
fun setDataSource(path: String): Boolean
|
fun setDataSource(path: String, force: Boolean): Boolean
|
||||||
|
|
||||||
fun setNextDataSource(path: String?)
|
fun setNextDataSource(path: String?)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue