2010-06-24 7 views
0

귀마개에서만 재생됩니다!iphone 오디오를 아래쪽의 "ipod"마이크에 재생하십시오.

내가 오디오 파일을 재생하기 전에

OSStatus status; // Describe audio component AudioComponentDescription desc; desc.componentType = kAudioUnitType_Output; desc.componentSubType = kAudioUnitSubType_RemoteIO; desc.componentFlags = 0; desc.componentFlagsMask = 0; desc.componentManufacturer = kAudioUnitManufacturer_Apple; // Get component AudioComponent inputComponent = AudioComponentFindNext(NULL, &desc); // Get audio units status = AudioComponentInstanceNew(inputComponent, &audioUnit); // Enable IO for recording UInt32 flag = 1; status = AudioUnitSetProperty(audioUnit, 
      kAudioOutputUnitProperty_EnableIO, 
      kAudioUnitScope_Input, 
      kInputBus, 
      &flag, 
      sizeof(flag)); // Enable IO for playback status = AudioUnitSetProperty(audioUnit, 
      kAudioOutputUnitProperty_EnableIO, 
      kAudioUnitScope_Output, 
      kOutputBus, 
      &flag, 
      sizeof(flag)); // Describe format audioFormat.mSampleRate = 44100; audioFormat.mFormatID = kAudioFormatLinearPCM; audioFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagIsPacked; audioFormat.mFramesPerPacket = 1; audioFormat.mChannelsPerFrame = 1; audioFormat.mBitsPerChannel = 16; audioFormat.mBytesPerPacket = 2; audioFormat.mBytesPerFrame = 2; 


    // Apply format status = AudioUnitSetProperty(audioUnit, 
      kAudioUnitProperty_StreamFormat, 
      kAudioUnitScope_Output, 
      kInputBus, 
      &audioFormat, 
      sizeof(audioFormat)); 
    status = AudioUnitSetProperty(audioUnit, 
      kAudioUnitProperty_StreamFormat, 
      kAudioUnitScope_Input, 
      kOutputBus, 
      &audioFormat, 
      sizeof(audioFormat)); AURenderCallbackStruct callbackStruct; // Set output callback callbackStruct.inputProc = playbackCallback; callbackStruct.inputProcRefCon = self; status = AudioUnitSetProperty(audioUnit, 
      kAudioUnitProperty_SetRenderCallback, 
      //kAudioUnitScope_Global, 
      kAudioUnitScope_Output, 
      kOutputBus, 
      &callbackStruct, 
      sizeof(callbackStruct)); // Set input callback 

    callbackStruct.inputProc = recordingCallback; callbackStruct.inputProcRefCon = self; status = AudioUnitSetProperty(audioUnit, 
      kAudioOutputUnitProperty_SetInputCallback, 

      //kAudioUnitScope_Global, 
      kAudioUnitScope_Input, 
      kInputBus, 
      &callbackStruct, 
      sizeof(callbackStruct)); 
    // Disable buffer allocation for the recorder (optional - do this if we want to pass in our own) flag = 0; status = AudioUnitSetProperty(audioUnit, 
      kAudioUnitProperty_ShouldAllocateBuffer, 
      kAudioUnitScope_Output, 
      kInputBus, 
      &flag, 
      sizeof(flag)); /* // TODO: Allocate our own buffers if we want 
*/ // Initialise status = AudioUnitInitialize(audioUnit); AudioUnitSetParameter(audioUnit, kHALOutputParam_Volume, 
     kAudioUnitScope_Input, kInputBus, 
     1, 0); 
+0

을 AVAudioSessionCategoryPlayback하는 AVAudioSession을 설정합니다. 귀하의 질문을 다시 고려하십시오. 실제 문제에 대한 자세한 정보를 제공합니다. 코드는 훌륭하지만 문맥이나 설명이 없으면 쓸모가 없습니다. – Jasarien

답변

0

을 재생 원격 IO를 사용하여, 당신이 요구하는지 아무 생각이

AVAudioSession * audioSession; 
[audioSession setCategory:AVAudioSessionCategoryPlayback error: &error]; 
//Activate the session 
[audioSession setActive:YES error: &error]; 
관련 문제