Iphone SDK записывает и воспроизводит музыку iPod - PullRequest
1 голос
/ 28 февраля 2012

Я сейчас нахожусь в процессе создания приложения для IOS, в их приложении есть код для измерения уровня громкости путем записи звука с микрофона в / dev / null, который я немедленно удаляю, но такжеэто мне нужно, чтобы иметь возможность проигрывать музыку с iPod одновременно.Из-за продолжающейся записи музыка остановлена ​​и не может быть запущена снова.

Я просмотрел документацию по разработке для Apple и до сих пор не смог понять, поэтому был бы признателен, если нетбыл опубликован просто лайк.

Кто-нибудь сможет взглянуть на приведенный ниже код и сказать мне, где я ошибаюсь, или подсказать мне другой способ получить уровень звука, который не заставляет 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);
    }
}

Спасибо за любую помощь Томас

...