私は現在、オーディオ録音をサポートするゲーム プロジェクトに取り組んでいます。このプログラムは、cocos2d-x のようなゲーム エンジンである WiEngine に基づいています。
これが問題です、私は多くの方法を試しましたが、[myRecorder Record] を呼び出すたびに、常に NO が返されます。次に、PrepareRecord を明示的に呼び出しましたが、どちらも No を返します。
レコーダーを初期化するコードは次のとおりです
- (void)initRecorder
{
if(self.myRecoder!=nil)
{
[self.myRecoder release];
self.myRecoder=nil;
}
NSDictionary *myRecorderParam = [[NSDictionary alloc]initWithObjectsAndKeys:
[NSNumber numberWithFloat:44100.0],AVSampleRateKey,
[NSNumber numberWithInt:kAudioFormatLinearPCM],AVFormatIDKey,
[NSNumber numberWithInt:16],AVLinearPCMBitDepthKey,
[NSNumber numberWithInt:1],AVNumberOfChannelsKey,
[NSNumber numberWithInt:AVAudioQualityMedium],AVEncoderAudioQualityKey,
nil];
NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *DocumentPath = [pathArray objectAtIndex:0];
DocumentPath = [DocumentPath stringByAppendingString:@"/luyin.wav"];
self.myRecoder = [[AVAudioRecorder alloc]initWithURL:[NSURL URLWithString:DocumentPath]
settings:myRecorderParam
error:nil];
[self.myRecoder setDelegate:self];
}
そして、私はこのようにレコードを呼び出しました
- (void)beginRecord
{
NSLog(@"begin record");
// AVAudioSession *audioSession = [AVAudioSession sharedInstance];
// NSError *err = nil;
// [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
// if(err){
// NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
// return;
// }
// err = nil;
// [audioSession setActive:YES error:&err];
// if(err){
// NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
// return;
// }
if(self.myRecoder==nil)
{
NSLog(@"recoder null");
}
BOOL resultPre = [[self myRecoder] prepareToRecord];
if(resultPre)
{
NSLog(@" record pre yes ");
}
else
{
NSLog(@" record pre no ");
}
BOOL result = [[self myRecoder] record];
if(result)
{
NSLog(@" record yes ");
}
else
{
NSLog(@" record no ");
}
}
NSLogs によると、初期化は失敗していないようです。
AudioSession も初期化しようとしましたが、どちらも機能しません
助けてください