English subtitles

← Creating a Path to Audio File - Intro to iOS App Development with Swift

Get Embed Code
3 Languages

Showing Revision 3 created 05/24/2016 by Udacity Robot.

  1. So here is the pseudo code on the top right.
  2. And the first step therein is to create a path to an audio file.
  3. Now I will need AVFoundation to work with audio.
  4. So what I've done is imported that framework at the top of my code here.
  5. Then I found an MP3 file of the movie quote I actually want to play from my app.
  6. This file currently resides on my desktop.
  7. By the way, it's also available for you to download in the instructor notes.
  8. To add this to our add what I will do is go back to Xcode,
  9. click on the file menu, and then click on Add Files to Pitch Perfect.
  10. And then simply add the MP3 file.
  11. Make sure this Copy items if needed box is checked.
  12. Okay, so now if you look in the Navigator,
  13. we've added the movie quote file to our project.
  14. I can drag it into the Supporting Files folder.
  15. All right, now that I have the MP3 file added to my project,
  16. I can get a handle on it inside viewDidLoad.
  17. Using the following piece of code.
  18. By the way, this code is also available in the instructor notes for you to use.
  19. So at this point I want you to use the Option key on your keyboard.
  20. And try and figure out what these things called NSBundle, mainBundle, and
  21. pathForResource are doing.
  22. Here is your question one more time.
  23. Enter your response in this box.