wake-ios/wake/Models/MediaType.swift
2025-09-01 19:42:32 +08:00

47 lines
1.2 KiB
Swift

import SwiftUI
import AVKit
/// Represents different types of media that can be displayed or processed
public enum MediaType: Equatable, Hashable {
case image(UIImage)
case video(URL, UIImage?) // URL is the video URL, UIImage is the thumbnail
public var thumbnail: UIImage? {
switch self {
case .image(let image):
return image
case .video(_, let thumbnail):
return thumbnail
}
}
public var isVideo: Bool {
if case .video = self {
return true
}
return false
}
public static func == (lhs: MediaType, rhs: MediaType) -> Bool {
switch (lhs, rhs) {
case (.image(let lhsImage), .image(let rhsImage)):
return lhsImage.pngData() == rhsImage.pngData()
case (.video(let lhsURL, _), .video(let rhsURL, _)):
return lhsURL == rhsURL
default:
return false
}
}
public func hash(into hasher: inout Hasher) {
switch self {
case .image(let image):
hasher.combine("image")
hasher.combine(image.pngData())
case .video(let url, _):
hasher.combine("video")
hasher.combine(url)
}
}
}