测试已测试 | ✗ |
语言编程语言 | SwiftSwift |
许可证 | MIT |
发布时间最新发布 | 2017年6月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Manish Kumar Pathak 维护。
MPAudioRecorder
这是一个库,您可以使用它将音频录音功能集成到应用程序中,它完全可定制,您可以在其中传递音频设置。
您可以使用 Cocoapods 或手动安装此库。
Cocoapods(如果需要或 Pod 安装出现任何错误,首先尝试 pod setup 或 pod repo update)
手动
像这样创建 MPAudioRecorder 的实例 // MPAudioRecorder,分配代理是强制性的。
let mpRecorder: MPAudioRecorder = MPAudioRecorder()
在视图加载时分配代理,以便可以调用所有相关代理方法
override func viewDidLoad()
{
super.viewDidLoad()
mpRecorder.delegateMPAR = self // Imp
}
如果需要,在您的视图控制器中导入 AVFoundation。
要开始录音,您可以使用一个函数,并通过您创建的 MPAudioRecorder 实例调用它:
mpRecorder.startAudioRecording()
要停止录音,您可以使用一个函数,并通过您创建的 MPAudioRecorder 实例调用它:
mpRecorder.stopAudioRecording()
You can implement all the delegates as per requirement with few mandatory delegate implementation.
A. AudioRecorderDidFinishRecording:successfully: is called when a recording has been finished or stopped.
This method is NOT called if the recorder is stopped due to an interruption.
func audioRecorderDidFinishRecording(_ recorder: AVAudioRecorder, successfully flag: Bool)
B. If an error occurs while encoding it will be reported to the delegate
func audioRecorderEncodeErrorDidOccur(_ recorder: AVAudioRecorder, error: Error?)
C. AVAudioRecorder INTERRUPTION NOTIFICATIONS ARE DEPRECATED - Use AVAudioSession instead. */
audioRecorderBeginInterruption: is called when the audio session has been interrupted while the recorder was
recording. The recorded file will be closed.
func audioRecorderBeginInterruption(_ recorder: AVAudioRecorder)
D. AudioRecorderEndInterruption:withOptions: is called when the audio session interruption has ended and this
recorder had been interrupted while recording.
Currently the only flag is AVAudioSessionInterruptionFlags_ShouldResume.
func audioRecorderEndInterruption(_ recorder: AVAudioRecorder, withOptions flags: Int)
用户可以使用的其他属性。
/// Settings, audio settings for a recorded audio.
public var audioSettings : [String : Int]?
/// File name, Name of the audio file with which user wants to save it.
public var audioFileName: String?
/// Custom url if any user wants to save the recorded Audio file at specific location.
public var customPath: String?
/// If the user wants the recorded audio filed to be saved to the iPhone's library # Coming soon.
public var shouldSaveToLibrary: Bool = false
/// If user want delegates methods to be implemented in their class.
public var delegateMPAR: MPAudioRecorderDelegate?
即将推出…
如果您有任何建议或看到改进的机会,请提出建议,因为这是我第一个 Cocoapods 库。
谢谢