Skip to content

Instantly share code, notes, and snippets.

@thatswiftguy
Last active January 14, 2023 08:12
Show Gist options
  • Save thatswiftguy/742c1b26e248c7465457df6622dab4d0 to your computer and use it in GitHub Desktop.
Save thatswiftguy/742c1b26e248c7465457df6622dab4d0 to your computer and use it in GitHub Desktop.
This Function will Play the Audio
func startPlaying(url : URL) {
let playSession = AVAudioSession.sharedInstance()
do {
try playSession.overrideOutputAudioPort(AVAudioSession.PortOverride.speaker)
} catch {
print("Playing failed in Device")
}
do {
audioPlayer = try AVAudioPlayer(contentsOf : url)
audioPlayer.prepareToPlay()
audioPlayer.play()
for i in 0..<recordingsList.count{
if recordingsList[i].fileURL == url{
recordingsList[i].isPlaying = true
}
}
} catch {
print("Playing Failed")
}
}
func stopPlaying(url : URL){
audioPlayer.stop()
for i in 0..<recordingsList.count {
if recordingsList[i].fileURL == url {
recordingsList[i].isPlaying = false
}
}
}
@ducduy20
Copy link

i can't see the project in github

@thatswiftguy
Copy link
Author

yeah bro, I am were mad to not commit the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment