- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我已经从苹果文档中读到关于 AVaudioRecorder 的信息 http://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html#//apple_ref/doc/uid/TP40009767-CH2-SW6
我发现了一个录音功能。但是我的代码崩溃了
[soundRecorder prepareToRecord];
我在谷歌上搜索了这么多。但我没有找到解决方案。我还找到了其他一些源代码。但它们也有同样的问题(在 prepareToRecord
上崩溃)。谁能帮帮我...
野兔是我的IBAction
- (IBAction) recordOrStop: (id) sender {
if (recording) {
[soundRecorder stop];
recording = NO;
self.soundRecorder = nil;
[recordOrStopButton setTitle: @"Record" forState:
UIControlStateNormal];
[recordOrStopButton setTitle: @"Record" forState:
UIControlStateHighlighted];
[[AVAudioSession sharedInstance] setActive: NO error: nil];
} else {
[[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryRecord
error: nil];
NSDictionary *recordSettings =
[[NSDictionary alloc] initWithObjectsAndKeys:
[NSNumber numberWithFloat: 44100.0], AVSampleRateKey,
[NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
[NSNumber numberWithInt: AVAudioQualityMax],
AVEncoderAudioQualityKey,
nil];
AVAudioRecorder *newRecorder =
[[AVAudioRecorder alloc] initWithURL: soundFileURL
settings: recordSettings
error: nil];
self.soundRecorder = newRecorder;
soundRecorder.delegate = self;
[soundRecorder prepareToRecord];
[soundRecorder record];
[recordOrStopButton setTitle: @"Stop" forState: UIControlStateNormal];
[recordOrStopButton setTitle: @"Stop" forState: UIControlStateHighlighted];
recording = YES;
}
我的 .h 文件
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
#import "MBProgressHUD.h"
@interface LyricsController : UIViewController<AVAudioSessionDelegate,AVAudioRecorderDelegate, MBProgressHUDDelegate>{
IBOutlet UITextView *LyricsView;
MBProgressHUD *HUD;
AVAudioRecorder * soundRecorder;
NSURL *soundFileURL;
BOOL recording;
BOOL playing;
__weak IBOutlet UIButton *recordOrStopButton;
}@property(strong,nonatomic)NSURL *soundFileURL;
@property(nonatomic,strong)AVAudioRecorder * soundRecorder;
最佳答案
只是因为你使用了断点。我遇到了同样的问题,我的代码没有崩溃,但它作为断点停止在 prepareTorecord
处,因为即使我没有在它上面放置任何断点。如果您禁用 xcode 的断点,它也会在模拟器上运行。
关于ios - prepareToRecord 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10719758/
我已经从苹果文档中读到关于 AVaudioRecorder 的信息 http://developer.apple.com/library/ios/#documentation/AudioVideo/C
prepareToRecord() 无明显原因返回 false。其他类似问题的解决方案都不适合我。这是我尝试过的: 在创建 AVAudioRecorder 之前立即开始录音 session (成功)。
我在跑 sample code关于录音(源代码可在文章末尾下载)。代码是这样的 NSArray *pathComponents = [NSArray arrayWithObjects:
当我使用代码时: @IBAction func recordAudio(sender: UIButton) { recordButton.enabled = false stopBu
我是一名优秀的程序员,十分优秀!