soundPlayer identifier error
Opened this issue · 1 comments
Im not sure why I am receiving this identifier error in the function call.
` func playerSetup() {
let audioFileName = getDocumentsDirector().appendingPathComponent(fileName)
do {
// Whats going on here? Defining a constant does not resolve the identifier in the function call
soundPlayer = try AVAudioPlayer(contentsOf: audioFileName)
soundPlayer.delegate = self
soundPlayer.prepareToPlay()
soundPlayer.volume = 1
} catch {
print(error)
}
}
`
when you create a property inside of a function, that property only exists within that function. To use a property in another function or elsewhere in the code, you must set that property as a global property; like you did towards the top of your code with audioPlayer AudioRecorder. Once you do that, you can just alter these properties within your function playerSetup before running soundPlayer.play() down at the bottom when the play button is pressed.
Also make sure to add your Privacy description in the info.plist for the microphone usage otherwise the app will crash immediately for trying to access the mic without user permission.
Hope this helps.