English subtitles

← Adding Code to Record and Stop Audio - Intro to iOS App Development with Swift

Get Embed Code
3 Languages

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

  1. All right, we're looking at RecordSoundsViewController right now.
  2. And what I've done here,
  3. is that I've embedded the code that we saw in the previous video in this file.
  4. Let me walk you through it.
  5. First I imported AVFoundation, and
  6. then I declared an object of AVAudioRecorder, globally.
  7. Then I added all of the code from the previous video,
  8. to the record audio function.
  9. This includes a print statement, which will print the name and
  10. the part of the file where we have recorded our voice.
  11. Now while I'm at it, let me add code to the Stop Audio function also.
  12. Here I will stop the audioRecorder, and then deactivate the audio session.
  13. I encourage you to Google and
  14. figure out why we need to add these two lines to our code.
  15. By the way, all of this code that we have added in this file,
  16. is available in the instructor notes for you to play with.
  17. All right. I'm going to run my project.
  18. So now when I hit the Record button,
  19. I get a print statement here in the debug area of my x code.
  20. This seems like the file name with the current date stamp that has been printed.
  21. Today is November 4th, 2014, and it's just past 12 p.m where I am.
  22. So it seems like the file name is correct.
  23. Okay, let me try this one more time and see if the time stamp actually changes.
  24. There.
  25. And it seems like it does.
  26. The time stamp now is looking at 12 p.m, 2 minutes and 36 seconds.
  27. One last thing to notice here,
  28. is that even though we've been able to successfully print the name of the file,
  29. we still don't know if our audio is being recorded successfully.
  30. Let's find out more about that in the next video.