0

I have a main menu view that includes a navigation link. When I press "play," it navigates to the game screen and plays a sound. However, the sound only plays for a second and then cuts off for the rest of the navigation. I need help to make the sound continuously play into the next view. Thank you in advance for your assistance.

NavigationLink(destination: GameScreenView(), isActive: $presentSound) {
    Button(action: {
//          SoundManager.instance.playSound(sound: .impact)
        DispatchQueue.main.asyncAfter(deadline: .now()) {
            SoundManager.instance.playSound(sound: .impact)
//          self.presentSound = true
    }
    }, label: {
    Text("Play")
    })
}

1 Answers1

0

Try the following approach, where you add an additional gesture to the NavigationLink, that plays a sound when the link is tapped.

struct ContentView: View {
    
    var body: some View {
        NavigationStack {
            NavigationLink(destination: Text("GameScreenView")) {
                Text("Play")
            }.simultaneousGesture(TapGesture().onEnded {
                AudioServicesPlaySystemSound(1026) // <-- for testing
                // SoundManager.instance.playSound(sound: .impact)
            })
        }
    }
}