mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-11-14 06:57:51 +00:00
ios: clamp voice and video durations (#8056)
This commit is contained in:
1 parent
76cc59eb7a
commit
b2e4731ec6
3 files changed
+18
-5
No files matched your search
@@ -534,9 +534,9 @@ struct CIVideoView: View {
|
||||
if let item = player.currentItem {
|
||||
let dur = CMTimeGetSeconds(item.duration)
|
||||
if !dur.isInfinite && !dur.isNaN {
|
||||
duration = Int(dur)
|
||||
duration = wholeSeconds(dur)
|
||||
}
|
||||
progress = Int(CMTimeGetSeconds(player.currentTime()))
|
||||
progress = wholeSeconds(CMTimeGetSeconds(player.currentTime()))
|
||||
// `if` prevents showing Play button while the playback seeks to start and then plays
|
||||
if player.currentTime() != player.currentItem?.duration && player.currentTime() != .zero {
|
||||
videoPlaying = player.timeControlStatus == .playing || player.timeControlStatus == .waitingToPlayAtSpecifiedRate
|
||||
|
||||
@@ -15,12 +15,16 @@ enum VoiceMessagePlaybackState {
|
||||
case paused
|
||||
}
|
||||
|
||||
func wholeSeconds(_ time: TimeInterval) -> Int {
|
||||
Int(exactly: time.rounded(.towardZero)) ?? 0
|
||||
}
|
||||
|
||||
func voiceMessageTime(_ time: TimeInterval) -> String {
|
||||
durationText(Int(time))
|
||||
durationText(wholeSeconds(time))
|
||||
}
|
||||
|
||||
func voiceMessageTime_(_ time: TimeInterval?) -> String {
|
||||
durationText(Int(time ?? 0))
|
||||
durationText(wholeSeconds(time ?? 0))
|
||||
}
|
||||
|
||||
struct ComposeVoiceView: View {
|
||||
@@ -157,7 +161,7 @@ struct ComposeVoiceView: View {
|
||||
var seek: (TimeInterval) -> Void
|
||||
|
||||
var body: some View {
|
||||
Slider(value: Binding(get: { progress ?? TimeInterval(0) }, set: { seek($0) }), in: 0 ... length)
|
||||
Slider(value: Binding(get: { progress ?? TimeInterval(0) }, set: { seek($0) }), in: 0 ... max(length, 0))
|
||||
.frame(maxWidth: .infinity)
|
||||
.frame(height: 4)
|
||||
.tint(theme.colors.primary)
|
||||
|
||||
@@ -160,6 +160,15 @@ final class SnapshotTests: XCTestCase {
|
||||
let rowHash = { (older: ChatItem) in ListItem(item: items[4], prevItem: items[5], nextItem: older, unreadBefore: 0).genHash(false, false) }
|
||||
XCTAssertNotEqual(rowHash(items[3]), rowHash(unreacted))
|
||||
}
|
||||
|
||||
func testVoiceMessageTimeFormatting() {
|
||||
XCTAssertEqual(voiceMessageTime(90), "01:30")
|
||||
XCTAssertEqual(voiceMessageTime(3600), "01:00:00")
|
||||
XCTAssertEqual(voiceMessageTime(TimeInterval(Int.max)), "00:00")
|
||||
XCTAssertEqual(voiceMessageTime(.nan), "00:00")
|
||||
XCTAssertEqual(voiceMessageTime_(nil), "00:00")
|
||||
XCTAssertEqual(voiceMessageTime_(TimeInterval(Int.max)), "00:00")
|
||||
}
|
||||
}
|
||||
|
||||
private func layoutCheckDir(_ env: [String: String]) -> URL {
|
||||
|
||||
Reference in new issue
Block a user