- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在创建的录音机应用程序中有两个函数(遵循 Udacity 教程。)我试图了解这两个函数是如何相关的:
@IBAction func recordButton(sender: UIButton) {
recordB.hidden = true
inProgress.hidden = false
stopButtonHide.hidden = false
let dirPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String
let currentDateTime = NSDate()
let formatter = NSDateFormatter()
formatter.dateFormat = "ddMMyyyy-HHmmss"
let recordingName = formatter.stringFromDate(currentDateTime)+".wav"
let pathArray = [dirPath, recordingName]
let filePath = NSURL.fileURLWithPathComponents(pathArray)
println(filePath)
var session = AVAudioSession.sharedInstance()
session.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)
audioRecorder = AVAudioRecorder(URL: filePath, settings: nil, error: nil)
audioRecorder.delegate = self
audioRecorder.meteringEnabled = true
audioRecorder.prepareToRecord()
audioRecorder.record()
}
func audioRecorderDidFinishRecording(recorder: AVAudioRecorder!, successfully flag: Bool) {
if(flag) {
recordedAudio = RecordedAudio()
recordedAudio.filePathUrl = recorder.url
recordedAudio.title = recorder.url.lastPathComponent
self.performSegueWithIdentifier("stopRecording", sender: recordedAudio)
} else {
println("Recording was not succesful")
recordB.enabled = true
stopButtonHide.hidden = true
}
}
第一个函数开始录音(据我所知),创建并存储一个音频文件(为其命名并获取路径。)第二个函数检查录音是否完成。我的问题是我看不到这两个函数是如何连接的。第二个函数如何知道检查第一个函数中的记录?有一个名为 RecordedAudio.swift 的单独类,它有两个变量:
import Foundation
class RecordedAudio: NSObject{
var filePathUrl: NSURL!
var title: String!
}
为什么我需要这门课?这个类的目的是什么(我知道它是 MVC 的模型部分,但仅此而已)?我试图了解我的代码中发生了什么,因为我在遵循的教程中并不清楚。
最佳答案
似乎 recordedAudio
是一个 RecordedAudio
对象,因此需要该类。
audioRecorderDidFinishRecording
是 ( as stated in the docs ) 一个 AVAudioRecorderDelegate
方法,并且会自动...
called by the system when a recording is stopped or has finished due to reaching its time limit.
在这种情况下,“录音”将指的是您在 recordButton:
中创建的 AVAudioRecorder
audioRecorder
(并且您为其创建已设置其 AVAudioRecorderDelegate
以触发 audioRecorderDidFinishRecording:
方法)。
关于ios - Swift -- 录音机/变声器应用程序 : How are these functions related?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28709299/
我是一名优秀的程序员,十分优秀!