Skip to content

Commit

Permalink
4.9.2 commit
Browse files Browse the repository at this point in the history
  • Loading branch information
XilinJia committed Apr 24, 2024
1 parent c2fb0f4 commit ae82900
Show file tree
Hide file tree
Showing 21 changed files with 416 additions and 2,341 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ android {
// Version code schema (not used):
// "1.2.3-beta4" -> 1020304
// "1.2.3" -> 1020395
versionCode 3020132
versionName "4.9.1"
versionCode 3020133
versionName "4.9.2"

def commit = ""
try {
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/java/ac/mdiq/podcini/playback/PlayableUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ object PlayableUtils {

if (playable is FeedMedia) {
val item = playable.item
if (item != null && item.isNew) {
DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.id)
}
if (item != null && item.isNew) DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.id)

if (playable.startPosition >= 0 && playable.getPosition() > playable.startPosition) {
playable.playedDuration = (playable.playedDurationWhenStarted
+ playable.getPosition() - playable.startPosition)
playable.playedDuration = (playable.playedDurationWhenStarted + playable.getPosition() - playable.startPosition)
}
DBWriter.setFeedMediaPlaybackInformation(playable)
}
Expand Down
57 changes: 16 additions & 41 deletions app/src/main/java/ac/mdiq/podcini/playback/PlaybackController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,13 @@ abstract class PlaybackController(private val activity: FragmentActivity) {
EventBus.getDefault().register(this)
eventsRegistered = true
}
if (PlaybackService.isRunning) {
initServiceRunning()
} else {
updatePlayButtonShowsPlay(true)
}
if (PlaybackService.isRunning) initServiceRunning()
else updatePlayButtonShowsPlay(true)
}

@Subscribe(threadMode = ThreadMode.MAIN)
fun onEventMainThread(event: PlaybackServiceEvent) {
if (event.action == PlaybackServiceEvent.Action.SERVICE_STARTED) {
init()
}
if (event.action == PlaybackServiceEvent.Action.SERVICE_STARTED) init()
}

@Synchronized
Expand All @@ -72,20 +67,16 @@ abstract class PlaybackController(private val activity: FragmentActivity) {
initialized = true

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
activity.registerReceiver(statusUpdate, IntentFilter(
PlaybackService.ACTION_PLAYER_STATUS_CHANGED), Context.RECEIVER_NOT_EXPORTED)
activity.registerReceiver(notificationReceiver, IntentFilter(
PlaybackServiceInterface.ACTION_PLAYER_NOTIFICATION), Context.RECEIVER_NOT_EXPORTED)
activity.registerReceiver(statusUpdate, IntentFilter(PlaybackService.ACTION_PLAYER_STATUS_CHANGED), Context.RECEIVER_NOT_EXPORTED)
activity.registerReceiver(notificationReceiver, IntentFilter(PlaybackServiceInterface.ACTION_PLAYER_NOTIFICATION), Context.RECEIVER_NOT_EXPORTED)
} else {
activity.registerReceiver(statusUpdate, IntentFilter(PlaybackService.ACTION_PLAYER_STATUS_CHANGED))
activity.registerReceiver(notificationReceiver, IntentFilter(PlaybackServiceInterface.ACTION_PLAYER_NOTIFICATION))
}

if (!released) {
bindToService()
} else {
throw IllegalStateException("Can't call init() after release() has been called")
}
if (!released) bindToService()
else throw IllegalStateException("Can't call init() after release() has been called")

checkMediaInfoLoaded()
}

Expand Down Expand Up @@ -157,10 +148,7 @@ abstract class PlaybackController(private val activity: FragmentActivity) {
if (!released) {
queryService()
Log.d(TAG, "Connection to Service established")
} else {
Log.i(TAG, "Connection to playback service has been established, " +
"but controller has already been released")
}
} else Log.i(TAG, "Connection to playback service has been established, but controller has already been released")
}
}

Expand Down Expand Up @@ -224,9 +212,7 @@ abstract class PlaybackController(private val activity: FragmentActivity) {
checkMediaInfoLoaded()
when (status) {
PlayerStatus.PLAYING -> updatePlayButtonShowsPlay(false)
PlayerStatus.PREPARING -> if (playbackService != null) {
updatePlayButtonShowsPlay(!playbackService!!.isStartWhenPrepared)
}
PlayerStatus.PREPARING -> if (playbackService != null) updatePlayButtonShowsPlay(!playbackService!!.isStartWhenPrepared)
PlayerStatus.FALLBACK, PlayerStatus.PAUSED, PlayerStatus.PREPARED, PlayerStatus.STOPPED, PlayerStatus.INITIALIZED ->
updatePlayButtonShowsPlay(true)
else -> {}
Expand Down Expand Up @@ -262,8 +248,7 @@ abstract class PlaybackController(private val activity: FragmentActivity) {
mediaInfoLoaded = false
handleStatus()
} else {
Log.e(TAG,
"queryService() was called without an existing connection to playbackservice")
Log.e(TAG, "queryService() was called without an existing connection to playbackservice")
}
}

Expand Down Expand Up @@ -362,9 +347,7 @@ abstract class PlaybackController(private val activity: FragmentActivity) {
}

fun speedForward(speed: Float) {
if (playbackService != null) {
playbackService!!.speedForward(speed)
}
playbackService?.speedForward(speed)
}

fun fallbackSpeed(speed: Float) {
Expand Down Expand Up @@ -392,9 +375,7 @@ abstract class PlaybackController(private val activity: FragmentActivity) {

val audioTracks: List<String>
get() {
if (playbackService?.audioTracks.isNullOrEmpty()) {
return emptyList()
}
if (playbackService?.audioTracks.isNullOrEmpty()) return emptyList()
return playbackService!!.audioTracks.filterNotNull().map { it }
}

Expand All @@ -409,15 +390,9 @@ abstract class PlaybackController(private val activity: FragmentActivity) {

val isPlayingVideoLocally: Boolean
get() = when {
PlaybackService.isCasting -> {
false
}
playbackService != null -> {
PlaybackService.currentMediaType == MediaType.VIDEO
}
else -> {
getMedia()?.getMediaType() == MediaType.VIDEO
}
PlaybackService.isCasting -> false
playbackService != null -> PlaybackService.currentMediaType == MediaType.VIDEO
else -> getMedia()?.getMediaType() == MediaType.VIDEO
}

val videoSize: Pair<Int, Int>?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,8 @@ abstract class PlaybackServiceMediaPlayer protected constructor(protected val co

if (newMedia != null && newStatus != PlayerStatus.INDETERMINATE) {
when {
oldPlayerStatus == PlayerStatus.PLAYING && newStatus != PlayerStatus.PLAYING -> {
callback.onPlaybackPause(newMedia, position)
}
oldPlayerStatus != PlayerStatus.PLAYING && newStatus == PlayerStatus.PLAYING -> {
callback.onPlaybackStart(newMedia, position)
}
oldPlayerStatus == PlayerStatus.PLAYING && newStatus != PlayerStatus.PLAYING -> callback.onPlaybackPause(newMedia, position)
oldPlayerStatus != PlayerStatus.PLAYING && newStatus == PlayerStatus.PLAYING -> callback.onPlaybackStart(newMedia, position)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,10 @@ object RewindAfterPauseUtils {
var rewindTime: Long = 0

when {
elapsedTime > ELAPSED_TIME_FOR_LONG_REWIND -> {
rewindTime = LONG_REWIND
}
elapsedTime > ELAPSED_TIME_FOR_MEDIUM_REWIND -> {
rewindTime = MEDIUM_REWIND
}
elapsedTime > ELAPSED_TIME_FOR_SHORT_REWIND -> {
rewindTime = SHORT_REWIND
}
elapsedTime > ELAPSED_TIME_FOR_LONG_REWIND -> rewindTime = LONG_REWIND
elapsedTime > ELAPSED_TIME_FOR_MEDIUM_REWIND -> rewindTime = MEDIUM_REWIND
elapsedTime > ELAPSED_TIME_FOR_SHORT_REWIND -> rewindTime = SHORT_REWIND
}

val newPosition = currentPosition - rewindTime.toInt()

return max(newPosition.toDouble(), 0.0).toInt()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package ac.mdiq.podcini.playback.service

import android.app.Notification
import android.content.Context
import androidx.core.app.NotificationCompat
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.session.CommandButton
import androidx.media3.session.DefaultMediaNotificationProvider
import androidx.media3.session.MediaNotification
import androidx.media3.session.MediaSession
import androidx.media3.session.*
import com.google.common.collect.ImmutableList

@UnstableApi
Expand All @@ -15,23 +14,22 @@ class CustomMediaNotificationProvider(context: Context) : DefaultMediaNotificati
override fun addNotificationActions(mediaSession: MediaSession, mediaButtons: ImmutableList<CommandButton>, builder: NotificationCompat.Builder, actionFactory: MediaNotification.ActionFactory): IntArray {

/* Retrieving notification default play/pause button from mediaButtons list. */
val defaultPlayPauseCommandButton = mediaButtons.getOrNull(0)
val notificationMediaButtons = if (defaultPlayPauseCommandButton != null) {
val defaultPlayPauseButton = mediaButtons.getOrNull(1)
val defaultRestartButton = mediaButtons.getOrNull(0)
val notificationMediaButtons = if (defaultPlayPauseButton != null) {
/* Overriding received mediaButtons list to ensure required buttons order: [rewind15, play/pause, forward15]. */
ImmutableList.builder<CommandButton>().apply {
add(NotificationPlayerCustomCommandButton.REWIND.commandButton)
add(defaultPlayPauseCommandButton)
add(NotificationPlayerCustomCommandButton.FORWARD.commandButton)
if (defaultRestartButton != null) add(defaultRestartButton)
add(NotificationCustomButton.REWIND.commandButton)
add(defaultPlayPauseButton)
add(NotificationCustomButton.FORWARD.commandButton)
add(NotificationCustomButton.SKIP.commandButton)
}.build()
} else {
/* Fallback option to handle nullability, in case retrieving default play/pause button fails for some reason (should never happen). */
mediaButtons
}
return super.addNotificationActions(
mediaSession,
notificationMediaButtons,
builder,
actionFactory
)
return super.addNotificationActions(mediaSession, notificationMediaButtons, builder, actionFactory)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,9 @@ class ExoPlayerWrapper internal constructor(private val context: Context) {
exoPlayer?.addListener(object : Player.Listener {
override fun onPlaybackStateChanged(playbackState: @Player.State Int) {
when {
audioCompletionListener != null && playbackState == Player.STATE_ENDED -> {
audioCompletionListener?.run()
}
playbackState == Player.STATE_BUFFERING -> {
bufferingUpdateListener?.accept(BUFFERING_STARTED)
}
else -> {
bufferingUpdateListener?.accept(BUFFERING_ENDED)
}
audioCompletionListener != null && playbackState == Player.STATE_ENDED -> audioCompletionListener?.run()
playbackState == Player.STATE_BUFFERING -> bufferingUpdateListener?.accept(BUFFERING_STARTED)
else -> bufferingUpdateListener?.accept(BUFFERING_ENDED)
}
}

Expand All @@ -87,21 +81,15 @@ class ExoPlayerWrapper internal constructor(private val context: Context) {
} else {
var cause = error.cause
if (cause is HttpDataSourceException) {
if (cause.cause != null) {
cause = cause.cause
}
}
if (cause != null && "Source error" == cause.message) {
cause = cause.cause
if (cause.cause != null) cause = cause.cause
}
if (cause != null && "Source error" == cause.message) cause = cause.cause
audioErrorListener?.accept(if (cause != null) cause.message else error.message)
}
}

override fun onPositionDiscontinuity(oldPosition: PositionInfo, newPosition: PositionInfo, reason: @DiscontinuityReason Int) {
if (reason == Player.DISCONTINUITY_REASON_SEEK) {
audioSeekCompleteListener?.run()
}
if (reason == Player.DISCONTINUITY_REASON_SEEK) audioSeekCompleteListener?.run()
}

override fun onAudioSessionIdChanged(audioSessionId: Int) {
Expand Down Expand Up @@ -218,6 +206,8 @@ class ExoPlayerWrapper internal constructor(private val context: Context) {
}

fun start() {
if (exoPlayer?.playbackState == Player.STATE_IDLE) prepare()

exoPlayer?.play()
// Can't set params when paused - so always set it on start in case they changed
exoPlayer!!.playbackParameters = playbackParameters
Expand Down Expand Up @@ -271,9 +261,7 @@ class ExoPlayerWrapper internal constructor(private val context: Context) {
val availableFormats = formats
for (i in 0 until trackSelections.length) {
val track = trackSelections[i] as ExoTrackSelection? ?: continue
if (availableFormats.contains(track.selectedFormat)) {
return availableFormats.indexOf(track.selectedFormat)
}
if (availableFormats.contains(track.selectedFormat)) return availableFormats.indexOf(track.selectedFormat)
}
return -1
}
Expand Down Expand Up @@ -309,9 +297,7 @@ class ExoPlayerWrapper internal constructor(private val context: Context) {
val oldEnhancer = this.loudnessEnhancer
if (oldEnhancer != null) {
newEnhancer.setEnabled(oldEnhancer.enabled)
if (oldEnhancer.enabled) {
newEnhancer.setTargetGain(oldEnhancer.targetGain.toInt())
}
if (oldEnhancer.enabled) newEnhancer.setTargetGain(oldEnhancer.targetGain.toInt())
oldEnhancer.release()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ import android.os.Bundle
import androidx.media3.session.CommandButton
import androidx.media3.session.SessionCommand

private const val CUSTOM_COMMAND_REWIND_ACTION_ID = "REWIND_15"
private const val CUSTOM_COMMAND_FORWARD_ACTION_ID = "FAST_FWD_15"
private const val CUSTOM_COMMAND_REWIND_ACTION_ID = "1_REWIND"
private const val CUSTOM_COMMAND_FORWARD_ACTION_ID = "2_FAST_FWD"
private const val CUSTOM_COMMAND_SKIP_ACTION_ID = "3_SKIP"

enum class NotificationPlayerCustomCommandButton(val customAction: String, val commandButton: CommandButton) {
enum class NotificationCustomButton(val customAction: String, val commandButton: CommandButton) {
SKIP(
customAction = CUSTOM_COMMAND_SKIP_ACTION_ID,
commandButton = CommandButton.Builder()
.setDisplayName("Skip")
.setSessionCommand(SessionCommand(CUSTOM_COMMAND_SKIP_ACTION_ID, Bundle()))
.setIconResId(R.drawable.ic_notification_skip)
.build(),
),
REWIND(
customAction = CUSTOM_COMMAND_REWIND_ACTION_ID,
commandButton = CommandButton.Builder()
Expand All @@ -24,5 +33,5 @@ enum class NotificationPlayerCustomCommandButton(val customAction: String, val c
.setSessionCommand(SessionCommand(CUSTOM_COMMAND_FORWARD_ACTION_ID, Bundle()))
.setIconResId(R.drawable.ic_notification_fast_forward)
.build(),
);
),
}

0 comments on commit ae82900

Please sign in to comment.