Add local Live Activity and Dynamic Island track display
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import ActivityKit
|
||||
import Foundation
|
||||
|
||||
struct MusicActivityAttributes: ActivityAttributes {
|
||||
struct ContentState: Codable, Hashable {
|
||||
var title: String
|
||||
var artist: String
|
||||
var playing: Bool
|
||||
var position: Double
|
||||
var duration: Double
|
||||
var updatedAt: Date
|
||||
var connected: Bool
|
||||
|
||||
// Bound UTF-8, including pathological combining characters, below ActivityKit's 4 KB limit.
|
||||
static func bounded(_ text: String) -> String {
|
||||
var result = ""
|
||||
for scalar in text.unicodeScalars {
|
||||
guard result.utf8.count + scalar.utf8.count <= 256 else { break }
|
||||
result.unicodeScalars.append(scalar)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
var progress: Double { duration > 0 ? min(1, max(0, position / duration)) : 0 }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user