Code Cleanup
This commit is contained in:
parent
7e3b4404cf
commit
4dc84c2564
4 changed files with 92 additions and 91 deletions
|
@ -9,6 +9,7 @@ import android.media.MediaPlayer
|
||||||
import android.media.audiofx.AudioEffect
|
import android.media.audiofx.AudioEffect
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.PowerManager
|
import android.os.PowerManager
|
||||||
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import code.name.monkey.retromusic.R
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
import code.name.monkey.retromusic.helper.MusicPlayerRemote
|
||||||
|
@ -296,6 +297,7 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
||||||
Toast.LENGTH_SHORT
|
Toast.LENGTH_SHORT
|
||||||
)
|
)
|
||||||
.show()
|
.show()
|
||||||
|
Log.e(TAG, what.toString() + extra)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,6 +356,10 @@ class CrossFadePlayer(val context: Context) : Playback, MediaPlayer.OnCompletion
|
||||||
override fun setCrossFadeDuration(duration: Int) {
|
override fun setCrossFadeDuration(duration: Int) {
|
||||||
crossFadeDuration = duration
|
crossFadeDuration = duration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val TAG: String = CrossFadePlayer::class.java.simpleName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun crossFadeScope(): CoroutineScope = CoroutineScope(Job() + Dispatchers.Main)
|
internal fun crossFadeScope(): CoroutineScope = CoroutineScope(Job() + Dispatchers.Main)
|
|
@ -330,6 +330,7 @@ public class MultiPlayer
|
||||||
context.getResources().getString(R.string.unplayable_file),
|
context.getResources().getString(R.string.unplayable_file),
|
||||||
Toast.LENGTH_SHORT)
|
Toast.LENGTH_SHORT)
|
||||||
.show();
|
.show();
|
||||||
|
Log.e(TAG, String.valueOf(what) + extra);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ import androidx.media.AudioManagerCompat
|
||||||
import androidx.media.MediaBrowserServiceCompat
|
import androidx.media.MediaBrowserServiceCompat
|
||||||
import androidx.media.session.MediaButtonReceiver.handleIntent
|
import androidx.media.session.MediaButtonReceiver.handleIntent
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import code.name.monkey.appthemehelper.util.VersionUtils.hasQ
|
import code.name.monkey.appthemehelper.util.VersionUtils
|
||||||
import code.name.monkey.retromusic.*
|
import code.name.monkey.retromusic.*
|
||||||
import code.name.monkey.retromusic.activities.LockScreenActivity
|
import code.name.monkey.retromusic.activities.LockScreenActivity
|
||||||
import code.name.monkey.retromusic.appwidgets.*
|
import code.name.monkey.retromusic.appwidgets.*
|
||||||
|
@ -93,10 +93,8 @@ import code.name.monkey.retromusic.volume.OnAudioVolumeChangedListener
|
||||||
import com.bumptech.glide.RequestBuilder
|
import com.bumptech.glide.RequestBuilder
|
||||||
import com.bumptech.glide.request.target.SimpleTarget
|
import com.bumptech.glide.request.target.SimpleTarget
|
||||||
import com.bumptech.glide.request.transition.Transition
|
import com.bumptech.glide.request.transition.Transition
|
||||||
import com.google.android.gms.cast.framework.media.MediaIntentReceiver
|
|
||||||
import org.koin.java.KoinJavaComponent.get
|
import org.koin.java.KoinJavaComponent.get
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Karim Abou Zeid (kabouzeid), Andrew Neal. Modified by Prathamesh More
|
* @author Karim Abou Zeid (kabouzeid), Andrew Neal. Modified by Prathamesh More
|
||||||
|
@ -824,8 +822,8 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
fun openTrackAndPrepareNextAt(position: Int): Boolean {
|
fun openTrackAndPrepareNextAt(position: Int): Boolean {
|
||||||
synchronized(this) {
|
|
||||||
this.position = position
|
this.position = position
|
||||||
val prepared = openCurrent()
|
val prepared = openCurrent()
|
||||||
if (prepared) {
|
if (prepared) {
|
||||||
|
@ -835,7 +833,6 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
notHandledMetaChangedForCurrentTrack = false
|
notHandledMetaChangedForCurrentTrack = false
|
||||||
return prepared
|
return prepared
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun pause() {
|
fun pause() {
|
||||||
Log.i(TAG, "Paused")
|
Log.i(TAG, "Paused")
|
||||||
|
@ -858,8 +855,8 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
fun play() {
|
fun play() {
|
||||||
synchronized(this) {
|
|
||||||
if (requestFocus()) {
|
if (requestFocus()) {
|
||||||
if (playback != null && !playback!!.isPlaying) {
|
if (playback != null && !playback!!.isPlaying) {
|
||||||
if (!playback!!.isInitialized) {
|
if (!playback!!.isInitialized) {
|
||||||
|
@ -901,7 +898,6 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
.show()
|
.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun playNextSong(force: Boolean) {
|
fun playNextSong(force: Boolean) {
|
||||||
playSongAt(getNextPosition(force))
|
playSongAt(getNextPosition(force))
|
||||||
|
@ -949,8 +945,8 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
fun prepareNextImpl() {
|
fun prepareNextImpl() {
|
||||||
synchronized(this) {
|
|
||||||
try {
|
try {
|
||||||
val nextPosition = getNextPosition(false)
|
val nextPosition = getNextPosition(false)
|
||||||
playback?.setNextDataSource(getTrackUri(getSongAt(nextPosition)))
|
playback?.setNextDataSource(getTrackUri(getSongAt(nextPosition)))
|
||||||
|
@ -958,7 +954,6 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun quit() {
|
fun quit() {
|
||||||
pause()
|
pause()
|
||||||
|
@ -1075,8 +1070,8 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
savePositionInTrack()
|
savePositionInTrack()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
fun seek(millis: Int): Int {
|
fun seek(millis: Int): Int {
|
||||||
synchronized(this) {
|
|
||||||
return try {
|
return try {
|
||||||
var newPosition = 0
|
var newPosition = 0
|
||||||
if (playback != null) {
|
if (playback != null) {
|
||||||
|
@ -1088,7 +1083,6 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
-1
|
-1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// to let other apps know whats playing. i.E. last.fm (scrobbling) or musixmatch
|
// to let other apps know whats playing. i.E. last.fm (scrobbling) or musixmatch
|
||||||
fun sendPublicIntent(what: String) {
|
fun sendPublicIntent(what: String) {
|
||||||
|
@ -1251,19 +1245,19 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
|
|
||||||
private fun startForegroundOrNotify() {
|
private fun startForegroundOrNotify() {
|
||||||
if (playingNotification != null && currentSong.id != -1L) {
|
if (playingNotification != null && currentSong.id != -1L) {
|
||||||
val isPlaying = isPlaying
|
if (!VersionUtils.hasS()) {
|
||||||
if (isForeground != isPlaying && !isPlaying) {
|
if (isForeground && !isPlaying) {
|
||||||
// This makes the notification dismissible
|
// This makes the notification dismissible
|
||||||
// We can't call stopForeground(false) on A12 though, which may result in crashes
|
// We can't call stopForeground(false) on A12 though, which may result in crashes
|
||||||
// when we call startForeground after that e.g. when Alarm goes off,
|
// when we call startForeground after that e.g. when Alarm goes off
|
||||||
if (VERSION.SDK_INT < VERSION_CODES.S) {
|
|
||||||
stopForeground(false)
|
stopForeground(false)
|
||||||
isForeground = false
|
isForeground = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isForeground && isPlaying) {
|
if (!isForeground) {
|
||||||
// Specify that this is a media service, if supported.
|
// Specify that this is a media service, if supported.
|
||||||
if (hasQ()) {
|
if (VersionUtils.hasQ()) {
|
||||||
startForeground(
|
startForeground(
|
||||||
PlayingNotification.NOTIFICATION_ID, playingNotification!!.build(),
|
PlayingNotification.NOTIFICATION_ID, playingNotification!!.build(),
|
||||||
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
|
ServiceInfo.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK
|
||||||
|
@ -1282,7 +1276,6 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun stopForegroundAndNotification() {
|
private fun stopForegroundAndNotification() {
|
||||||
|
@ -1291,9 +1284,9 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
isForeground = false
|
isForeground = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
private fun openCurrent(): Boolean {
|
private fun openCurrent(): Boolean {
|
||||||
synchronized(this) {
|
return try {
|
||||||
try {
|
|
||||||
if (playback != null) {
|
if (playback != null) {
|
||||||
return playback!!.setDataSource(
|
return playback!!.setDataSource(
|
||||||
getTrackUri(
|
getTrackUri(
|
||||||
|
@ -1302,14 +1295,12 @@ class MusicService : MediaBrowserServiceCompat(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
} else false
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
return false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun playFromPlaylist(intent: Intent) {
|
private fun playFromPlaylist(intent: Intent) {
|
||||||
val playlist: AbsSmartPlaylist? = intent.getParcelableExtra(INTENT_EXTRA_PLAYLIST)
|
val playlist: AbsSmartPlaylist? = intent.getParcelableExtra(INTENT_EXTRA_PLAYLIST)
|
||||||
|
|
|
@ -46,7 +46,10 @@ import code.name.monkey.retromusic.util.PreferenceUtil
|
||||||
import code.name.monkey.retromusic.util.RetroColorUtil
|
import code.name.monkey.retromusic.util.RetroColorUtil
|
||||||
import com.bumptech.glide.request.target.CustomTarget
|
import com.bumptech.glide.request.target.CustomTarget
|
||||||
import com.bumptech.glide.request.transition.Transition
|
import com.bumptech.glide.request.transition.Transition
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
class PlayingNotificationImpl24(
|
class PlayingNotificationImpl24(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue