How can I play a specific sound from an Array?

How can I play a specific sound from an Array?

In my app, I’ve set the option to play, when the user tap a button, an audio description when an image is recognised, but I can’t select which file I want to play. My audio file are store in inside an array<a href="https://i.stack.imgur.com/pbX55.jpg" target="_blank"><img src="https://i.stack.imgur.com/pbX55.jpg"></a>

In my app, I’ve set the option to play, when the user tap a button, an audio description when an image is recognised, but I can’t select which file I want to play. My audio file are store in inside an array

Here’s the code that I use to play the single audio file:

func listenAudio(){

guard let url = Bundle.main.url(forResource: "afraid-of-destiny", withExtension: ".mp3") else { return }

do {
    try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default)
    try AVAudioSession.sharedInstance().setActive(true)

    self.player = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileType.mp3.rawValue)

    guard let player = self.player else { return }

    player.play()

    self.audioButton.setTitle("Stop", for: UIControl.State.normal)
    self.player!.play()


} catch let error {
    print(error.localizedDescription)
}

}

I thought to use an if/else, but it doesn’t work

ios swift

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Hire Dedicated Swift Developers

Want to create a native iOS application for your Startup? **[Hire Dedicated Swift Developers](https://hourlydeveloper.io/hire-dedicated-swift-developer/ "Hire Dedicated Swift Developers")** for end-to-end services like development, migration...

iOS App Development: How Apple's iOS 13 & Swift 5 Will Change App Development Industry

Want to know how Apple's iOS 13 & Swift 5 will change the iOS app development industry? Refer to this blog that contains in-detail information on it.

Easy way to save the class object in user defaults - Swift iOS

Easy way to save the class object in user defaults - Swift iOS Text tutorial: http://adnan-tech.com/easy-way-to-save-the-class-object-in-user-defaults-swift-...

The ultimate guide to iOS Unit Testing with Swift and Xcode

Unit testing is a testing method where you can test “unit” of code whether it is working as you want or not. In Xcode, use XCTest…

How to upload single and multiple images in iOS Swift, PHP and MySQL

How to upload single and multiple images in iOS Swift, PHP, and MySQL.