51 lines
1.6 KiB
Swift
51 lines
1.6 KiB
Swift
import SwiftUI
|
|
|
|
struct NoiseView: View {
|
|
@State private var player = NoisePlayer()
|
|
let sounds = [
|
|
Sound(name: "White Noise", fileName: "white-noise.mp3"),
|
|
Sound(name: "Heavy Rain White Noise", fileName: "heavy-rain-white-noise.mp3"),
|
|
Sound(name: "Fan White Noise", fileName: "fan-white-noise-heater-303207.mp3")
|
|
// Add more sounds here, matching your bundled MP3s
|
|
]
|
|
|
|
@State private var selectedSound: Sound?
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Text("White/Pink Noise")
|
|
.font(.headline)
|
|
|
|
Picker("Select Noise", selection: $selectedSound) {
|
|
Text("Choose a sound").tag(nil as Sound?) // Placeholder
|
|
ForEach(sounds) { sound in
|
|
Text(sound.name).tag(sound as Sound?)
|
|
}
|
|
}
|
|
.pickerStyle(.menu)
|
|
|
|
HStack {
|
|
Button(player.isPlaying ? "Stop" : "Play") {
|
|
if player.isPlaying {
|
|
player.stopSound()
|
|
} else if let sound = selectedSound {
|
|
player.playSound(sound)
|
|
}
|
|
}
|
|
.padding()
|
|
.background(player.isPlaying ? Color.red : Color.green)
|
|
.foregroundColor(.white)
|
|
.cornerRadius(8)
|
|
.disabled(selectedSound == nil) // Disable if no sound selected
|
|
}
|
|
|
|
// Add premium unlock button here later (e.g., In-App Purchase)
|
|
}
|
|
.padding()
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
NoiseView()
|
|
}
|