Add iOS platform service boundaries
This commit is contained in:
@@ -264,8 +264,15 @@ public final class ProfileViewModel: ObservableObject {
|
||||
public final class MediaViewModel: ObservableObject {
|
||||
@Published public private(set) var activePhotoPath: String?
|
||||
@Published public private(set) var activeVoicePath: String?
|
||||
@Published public private(set) var isVoicePlaying = false
|
||||
|
||||
public init() {}
|
||||
private let cache: MediaCache?
|
||||
private let voicePlayer: VoicePlayback?
|
||||
|
||||
public init(cache: MediaCache? = nil, voicePlayer: VoicePlayback? = nil) {
|
||||
self.cache = cache
|
||||
self.voicePlayer = voicePlayer
|
||||
}
|
||||
|
||||
public func showPhoto(path: String) {
|
||||
activePhotoPath = path
|
||||
@@ -274,4 +281,27 @@ public final class MediaViewModel: ObservableObject {
|
||||
public func showVoice(path: String) {
|
||||
activeVoicePath = path
|
||||
}
|
||||
|
||||
public func cachedPhotoPath(fileId: Int32) -> URL? {
|
||||
cache?.photoPath(fileId: fileId)
|
||||
}
|
||||
|
||||
public func cachedVoicePath(fileId: Int32) -> URL? {
|
||||
cache?.voicePath(fileId: fileId)
|
||||
}
|
||||
|
||||
public func playVoice(url: URL) async {
|
||||
do {
|
||||
try await voicePlayer?.load(url: url)
|
||||
await voicePlayer?.play()
|
||||
isVoicePlaying = true
|
||||
} catch {
|
||||
isVoicePlaying = false
|
||||
}
|
||||
}
|
||||
|
||||
public func pauseVoice() async {
|
||||
await voicePlayer?.pause()
|
||||
isVoicePlaying = false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user