Simon Plooy
Simon Plooy

Reputation: 23

how can I display and load audio files from iOS app resource/asset folder?

I am fresh to programming and have chosen to learn swift as my first language. I have started playing with the AVFoundation framework. In this case I am working with AVAudioPlayer.

I currently have audio files being loaded through NSURL using the file name and type but I would like to be able to load audio files for each instance of AVAudioPlayer from a list or menu that displays the files currently in the app's resource folder.

This is how I am currently loading my audio files:

var audioPlayer = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath:     NSBundle.mainBundle().pathForResource( "test_kick", ofType: "wav")!),    error: nil)

I have searched for hours with no luck and really don't know where to start with this. Any help would be greatly appreciated!

Upvotes: 2

Views: 2192

Answers (1)

Dennis Weidmann
Dennis Weidmann

Reputation: 1967

Simon, if I understand your question right, you know how to load a file from the assets, but you want to show a list of the files and play it after a click on a specific file, is that right?

Therefore you will first have to list the folder contents in an UITableView, and react on the click from that TableView to load the selected file into your AVPlayer...

NSFileManager.defaultManager().contentsOfDirectoryAtPath("your path", error: nil)

The above code will give you an array of files inside the path you already have, to be represented in an UITableView

Do you know how to build up a UITableViewDataSource and Delegate?

Upvotes: 2

Related Questions