Code + Identity-Rename zur Vorbereitung auf Apple-Dev-Portal-Aktion (Bundle ev.mana.wordeck, App-Group group.ev.mana.wordeck, AASA applinks:wordeck.com). Build bleibt funktional, aber gegen die neue text-only-API können image-occlusion-Creates 422 zurückgeben — das wird mit der Wordeck-Native v1.0-Welle (parallele Apple-Aktion) sauber gemacht. Umbenennung: - 41 Files: cardecky/Cardecky → wordeck/Wordeck (Display, Strings, Kommentare) - 57 Files: CardsNative → WordeckNative, CardsAPI → WordeckAPI, CardsTheme → WordeckTheme, CardsBrand → WordeckBrand, CardsWidget → WordeckWidget, CardsDueWidget → WordeckDueWidget - Bundle-ID ev.mana.cardecky → ev.mana.wordeck (project.yml, Info.plist, entitlements, Keychain-Service, App-Group) - AASA applinks:cardecky.mana.how → applinks:wordeck.com - API-Base cardecky-api.mana.how → api.wordeck.com - 10 Files renamed (App-Entry, API-Extensions, Theme, Widget, Entitlements, Tests) - xcodeproj regenerated via xcodegen → WordeckNative.xcodeproj - MaskRegionsTests.swift gelöscht (image-occlusion entfällt mit Wordeck text-only) Forgejo-Repo git.mana.how/till/cards-native → wordeck-native umbenannt (Auto-Redirect aktiv). Lokales Verzeichnis Code/cards-native/ bleibt vorerst — wird beim nächsten Apple-Setup mit Bundle-Test umbenannt. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
75 lines
2.3 KiB
Swift
75 lines
2.3 KiB
Swift
import AVFoundation
|
|
import SwiftUI
|
|
|
|
/// Audio-Wiedergabe-Button für `audio-front`-Karten. Lädt das File einmal
|
|
/// per MediaCache, spielt mit AVAudioPlayer ab.
|
|
struct AudioPlayerButton: View {
|
|
let mediaId: String
|
|
|
|
@Environment(\.mediaCache) private var mediaCache
|
|
@State private var player: AVAudioPlayer?
|
|
@State private var isPlaying = false
|
|
@State private var failed = false
|
|
|
|
var body: some View {
|
|
Button {
|
|
togglePlayback()
|
|
} label: {
|
|
HStack(spacing: 12) {
|
|
Image(systemName: failed
|
|
? "speaker.slash.fill"
|
|
: (isPlaying ? "pause.circle.fill" : "play.circle.fill"))
|
|
.font(.system(size: 48))
|
|
.foregroundStyle(failed ? WordeckTheme.error : WordeckTheme.primary)
|
|
Text(failed ? "Audio nicht verfügbar" : (isPlaying ? "Wiedergabe läuft" : "Anhören"))
|
|
.font(.headline)
|
|
.foregroundStyle(WordeckTheme.foreground)
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
.padding(20)
|
|
.background(WordeckTheme.surface, in: RoundedRectangle(cornerRadius: 12))
|
|
.overlay(
|
|
RoundedRectangle(cornerRadius: 12)
|
|
.stroke(WordeckTheme.border, lineWidth: 1)
|
|
)
|
|
}
|
|
.buttonStyle(.plain)
|
|
.disabled(failed)
|
|
.task(id: mediaId) {
|
|
await load()
|
|
}
|
|
.onDisappear {
|
|
player?.stop()
|
|
isPlaying = false
|
|
}
|
|
}
|
|
|
|
private func load() async {
|
|
guard let cache = mediaCache else { failed = true
|
|
return
|
|
}
|
|
do {
|
|
let data = try await cache.data(for: mediaId)
|
|
#if canImport(UIKit)
|
|
try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
|
|
try AVAudioSession.sharedInstance().setActive(true)
|
|
#endif
|
|
player = try AVAudioPlayer(data: data)
|
|
player?.prepareToPlay()
|
|
} catch {
|
|
failed = true
|
|
}
|
|
}
|
|
|
|
private func togglePlayback() {
|
|
guard let player else { return }
|
|
if player.isPlaying {
|
|
player.pause()
|
|
isPlaying = false
|
|
} else {
|
|
player.currentTime = 0
|
|
player.play()
|
|
isPlaying = true
|
|
}
|
|
}
|
|
}
|