gpt4 book ai didi

ios - prepareToRecord 崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:50:44 26 4
gpt4 key购买 nike

我已经从苹果文档中读到关于 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com