Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class AudioPlaybackManager @Inject constructor(
private val TAG = "AudioPlaybackManager"

private val _playbackState =
MutableStateFlow<AudioPlaybackState>(AudioPlaybackState.Idle)
MutableStateFlow<AudioPlaybackState>(AudioPlaybackState.Idle(1f))
val playbackState: StateFlow<AudioPlaybackState> = _playbackState.asStateFlow()

// Keeping certain aspect different from the state, like audio ending, which is more an event
Expand Down Expand Up @@ -156,8 +156,10 @@ class AudioPlaybackManager @Inject constructor(
stopProgressTracking()
controller?.stop()
controller?.clearMediaItems()

val speed = currentPlayable?.let { getSavedState(it.messageId).playbackSpeed } ?: 1f
currentPlayable = null
_playbackState.value = AudioPlaybackState.Idle
_playbackState.value = AudioPlaybackState.Idle(speed)
}

fun seekTo(positionMs: Long) {
Expand Down Expand Up @@ -385,7 +387,9 @@ class AudioPlaybackManager @Inject constructor(
false
)
} else {
AudioPlaybackState.Idle
AudioPlaybackState.Idle(
saved.playbackSpeed
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sealed class AudioPlaybackState(
}
}

data object Idle : AudioPlaybackState(1f)
data class Idle(override val playbackSpeed: Float = 1f) : AudioPlaybackState(playbackSpeed)

sealed class Active(
open val playable: PlayableAudio,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class MessageDetailsViewModel @AssistedInject constructor(

private val Slide.details: List<TitledText>
get() = listOfNotNull(
TitledText(R.string.attachmentsFileId, filename),
TitledText(R.string.attachmentsFileId, asAttachment().location), //File ID isn't the filename but the ID on the file server
TitledText(R.string.attachmentsFileType, asAttachment().contentType),
TitledText(R.string.attachmentsFileSize, Formatter.formatFileSize(context, fileSize)),
takeIf { it is ImageSlide }
Expand All @@ -235,7 +235,10 @@ class MessageDetailsViewModel @AssistedInject constructor(
private fun AttachmentDatabase.duration(slide: Slide): String? =
slide.takeIf { it.hasAudio() }
?.run { asAttachment() as? DatabaseAttachment }
?.run { getAttachmentAudioExtras(attachmentId)?.durationMs }
?.run {
getAttachmentAudioExtras(attachmentId)?.durationMs
?: this.audioDurationMs
}
?.takeIf { it > 0 }
?.let {
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ class VoiceMessageView @JvmOverloads constructor(
binding.voiceMessageSpeedButton.setTextColor(textColor)
}

// text
// duration
this.durationMs = playable?.durationMs?.coerceAtLeast(0) ?: 0L
binding.voiceMessageViewDurationTextView.text =
MediaUtil.getFormattedVoiceMessageDuration(this.durationMs)

// title
binding.audioTitle.text = if(playable?.isVoiceNote == true) context.getString(R.string.messageVoice)
else playable?.filename ?: context.getString(R.string.unknown)

Expand Down Expand Up @@ -194,7 +199,7 @@ class VoiceMessageView @JvmOverloads constructor(
is AudioPlaybackState.Idle -> {
isPlaying = false
binding.voiceMessageViewLoader.isVisible = false
updateSeekBar(0, 0) // Reset
updateSeekBar(0, this.durationMs) // Reset
renderIcon()
}
is AudioPlaybackState.Active.Loading -> {
Expand Down