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

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!

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?

Related

How to let AVPlayer plays mp3 from URL without waiting to load the whole file in swift

I am playing a file using AVPlayer and it is working fine. What I am looking for is that when the application plays the file it should play as soon as some enough buffer available. Currently what I have noticed is that if the file is big it waits for longer time to start playing the file which means it waits until the file is loaded in the buffer or so.
Any thoughts?
First, thank you Paul, your hint helped.
I have resolved the issue as follow:
Instead of having the URL as the mp3 file; I have created a text file and called it audio.m3u then I have just wrote the url address of my mp3 file in the newly created file (the m3u). Then played the file (audio.m3u) in the AVPlayer.
thats all :)

Get asset into a sound buffer

I'm playing around with this code example.
What I am trying to do is create a 100% Swift iOS version of this metronome app that allows playing of the MoreCowbell.caf file similar to how they have already done in the macOS example.
It makes logical sense that IF there were some way to reference this MoreCowbell.caf "asset"/"resource" (?) using the URL format, then the above code could work.
Is there a way to do that? If not, then how can we refer to MoreCowbell.caf from code in order get those ones and zeros into the sound buffer?
I have done much googling and looking at apple documentation but and going in circles so thank you for any help!
You can get a URL to files in your Bundle (ie. in your App) by using a method on Bundle (or NSBundle when using Objective-C). It works like this:
let fileURL = Bundle.main.url(forResource: "MoreCowbell", withExtension: "caf")
You can find more information on this in the official documentation.
Also make sure that the file MoreCowbell.caf is included in your Bundle. You do that by setting it's Target Membership

MonoGame cannot load a Song as a non-content file

I've created a game in XNA 4.0 and now want to port it to MonoGame. I'm using the exact same code for my LoadContent method as I did in the original game. However, MonoGame fails to load a song from the content folder and returns an error saying Could not load Example asset as a non-content file. I'm using the following line of code to do it.
Song song = songLoader.Load<Song>("Example");
The song is in the WMA format with a compiled XNB file in the same folder. Both files are set to "Copy if newer". How do I fix the problem?

Playing mp3 in URL (swift2)

I want to build a program that reads a certain code (ex: deb_prel), and if the
url = "http://www.piano-midi.de/mp3/BFFCEDC41B391847DAE02F6A5EA1E1A8/" +code.text! +".mp3"
exists, plays after the search button is clicked, and with a play/pause and adjust volume.
I have already built the storyboard (easy part), but I am having difficulties to build this simple program. I don't known where to begin, can anyone help me?
I would suggest to dig deep in AVFoundation here and AVAudioPlayerDelegate here. Also check this as reference for playing/pausing and recording audio files.

PPTx with embedded video play on iOS

I am making an application which should be able to play any videos embedded in a PPTx. Currently using Quicklook Framework for iOS I am able to see the text or any images but not able to play the video. I thought of one solution as, Converting the PPTx to zip and then parse the XML files to give the video and then play, which doesn't look very practical as it needs to be done for every file where the structure keeps changing with very slide/PPT Slideshark is able to play videos embedded in a PPT. Any Ideas on how to achieve this ?
Converting PPTs into HTML5 is one of the solution.

Resources