Iphone SDK录制和播放iPod音乐

时间:2012-02-28 00:03:46

标签: ios avaudioplayer audio-recording ios5

我目前正在为IOS拧一个应用程序,他们的应用程序有代码通过将麦克风的音频录制到/ dev / null来对音量水平进行采样,我会立即将其删除,但同时也是这个我需要能够同时播放iPod音乐。由于正在进行录制,音乐会停止,无法再次启动。

我查看了苹果开发文档,到目前为止我还无法理解,所以如果不仅仅发布了这样的内容,我将不胜感激。

是否有人能够查看下面的代码并告诉我哪里出错了,或者告诉我采用另一种方式来获取不会让iDevice停止播放音乐的音频级别。

- (void)startAudioSampler {

//Check to see if the sampler is already set.
if (audioSampler == nil) {

    //It is not set up, so set it up.
    //Set up the location as it needs to save as a recording, so save it to /dev/null which should delete straight away.
    NSURL *url = [NSURL fileURLWithPath:@"/dev/null"];

    //Set up the settings for the sampler.
    NSDictionary *settings = [NSDictionary dictionaryWithObjectsAndKeys:
                              [NSNumber numberWithFloat: 44100.0],                 AVSampleRateKey,
                              [NSNumber numberWithInt: kAudioFormatAppleLossless], AVFormatIDKey,
                              [NSNumber numberWithInt: 1],                         AVNumberOfChannelsKey,
                              nil];
    //Create the error for it to report to.
    NSError *error;

    //Create the sampler.
    audioSampler = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];
    //Check it set up correctly.
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];
    if (audioSampler != nil) {
        //Start the sampler.
        [audioSampler prepareToRecord];
        audioSampler.meteringEnabled = YES;
        [audioSampler record];

        //Set to sampler every 0.03 seconds (by running the updateInputAudioLevel every 0.03 seconds).
        samplerUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(updateInputAudioLevel) userInfo:nil repeats:YES];
    } else {
        //There was an error during the set up so report it to the log.
        NSLog(@"%@", error.description);
    }
}

感谢您的帮助 托马斯

0 个答案:

没有答案
相关问题