fix iOS media duration deprecation
This commit is contained in:
@@ -31,7 +31,7 @@ final class HermesRepository: ObservableObject {
|
|||||||
errorCause = nil
|
errorCause = nil
|
||||||
mockRoundIndex = 0
|
mockRoundIndex = 0
|
||||||
currentSession = MockHermesData.session(localeCode: localeCode, appVersion: appVersion)
|
currentSession = MockHermesData.session(localeCode: localeCode, appVersion: appVersion)
|
||||||
currentRound = MockHermesData.round(index: mockRoundIndex, now: Date())
|
currentRound = await MockHermesData.round(index: mockRoundIndex, now: Date())
|
||||||
isLoading = false
|
isLoading = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ final class HermesRepository: ObservableObject {
|
|||||||
isLoading = true
|
isLoading = true
|
||||||
errorCause = nil
|
errorCause = nil
|
||||||
mockRoundIndex = (mockRoundIndex + 1) % MockHermesData.roundCount
|
mockRoundIndex = (mockRoundIndex + 1) % MockHermesData.roundCount
|
||||||
let round = MockHermesData.round(index: mockRoundIndex, now: Date())
|
let round = await MockHermesData.round(index: mockRoundIndex, now: Date())
|
||||||
currentRound = round
|
currentRound = round
|
||||||
isLoading = false
|
isLoading = false
|
||||||
return round
|
return round
|
||||||
@@ -193,9 +193,9 @@ enum MockHermesData {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
static func round(index: Int, now: Date) -> HermesRound {
|
static func round(index: Int, now: Date) async -> HermesRound {
|
||||||
let scenarios = [
|
let scenarios = [
|
||||||
scenario(
|
await scenario(
|
||||||
eventID: "10000000-0000-0000-0000-000000000001",
|
eventID: "10000000-0000-0000-0000-000000000001",
|
||||||
marketID: "20000000-0000-0000-0000-000000000001",
|
marketID: "20000000-0000-0000-0000-000000000001",
|
||||||
yesOutcomeID: "30000000-0000-0000-0000-000000000001",
|
yesOutcomeID: "30000000-0000-0000-0000-000000000001",
|
||||||
@@ -205,7 +205,7 @@ enum MockHermesData {
|
|||||||
winningOutcomeID: "30000000-0000-0000-0000-000000000001",
|
winningOutcomeID: "30000000-0000-0000-0000-000000000001",
|
||||||
now: now
|
now: now
|
||||||
),
|
),
|
||||||
scenario(
|
await scenario(
|
||||||
eventID: "10000000-0000-0000-0000-000000000011",
|
eventID: "10000000-0000-0000-0000-000000000011",
|
||||||
marketID: "20000000-0000-0000-0000-000000000011",
|
marketID: "20000000-0000-0000-0000-000000000011",
|
||||||
yesOutcomeID: "30000000-0000-0000-0000-000000000011",
|
yesOutcomeID: "30000000-0000-0000-0000-000000000011",
|
||||||
@@ -215,7 +215,7 @@ enum MockHermesData {
|
|||||||
winningOutcomeID: "30000000-0000-0000-0000-000000000012",
|
winningOutcomeID: "30000000-0000-0000-0000-000000000012",
|
||||||
now: now
|
now: now
|
||||||
),
|
),
|
||||||
scenario(
|
await scenario(
|
||||||
eventID: "10000000-0000-0000-0000-000000000021",
|
eventID: "10000000-0000-0000-0000-000000000021",
|
||||||
marketID: "20000000-0000-0000-0000-000000000021",
|
marketID: "20000000-0000-0000-0000-000000000021",
|
||||||
yesOutcomeID: "30000000-0000-0000-0000-000000000021",
|
yesOutcomeID: "30000000-0000-0000-0000-000000000021",
|
||||||
@@ -239,11 +239,11 @@ enum MockHermesData {
|
|||||||
sourceRef: String,
|
sourceRef: String,
|
||||||
winningOutcomeID: String,
|
winningOutcomeID: String,
|
||||||
now: Date
|
now: Date
|
||||||
) -> HermesRound {
|
) async -> HermesRound {
|
||||||
let mediaURL = localMediaURL(named: "example-round.mov") ?? fallbackMediaURL
|
let mediaURL = localMediaURL(named: "example-round.mov") ?? fallbackMediaURL
|
||||||
let previewDurationMs = assetDurationMs(url: mediaURL) ?? 15_000
|
let previewDurationMs = await assetDurationMs(url: mediaURL) ?? 15_000
|
||||||
let revealURL = revealMediaURL()
|
let revealURL = revealMediaURL()
|
||||||
let revealDurationMs = assetDurationMs(url: revealURL) ?? 6_000
|
let revealDurationMs = await assetDurationMs(url: revealURL) ?? 6_000
|
||||||
let lockAt = now.addingTimeInterval(Double(previewDurationMs) / 1_000.0)
|
let lockAt = now.addingTimeInterval(Double(previewDurationMs) / 1_000.0)
|
||||||
let settleAt = lockAt.addingTimeInterval(6)
|
let settleAt = lockAt.addingTimeInterval(6)
|
||||||
|
|
||||||
@@ -346,8 +346,11 @@ enum MockHermesData {
|
|||||||
return FileManager.default.fileExists(atPath: candidate.path) ? candidate : nil
|
return FileManager.default.fileExists(atPath: candidate.path) ? candidate : nil
|
||||||
}
|
}
|
||||||
|
|
||||||
private static func assetDurationMs(url: URL) -> Int? {
|
private static func assetDurationMs(url: URL) async -> Int? {
|
||||||
let duration = AVAsset(url: url).duration.seconds
|
let asset = AVURLAsset(url: url)
|
||||||
|
guard let duration = try? await asset.load(.duration).seconds else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
guard duration.isFinite, duration > 0 else {
|
guard duration.isFinite, duration > 0 else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user