AudioUnit framework not found

2019-08-06 00:59发布

问题:

I am implementing an audio based application, in that I need to play both application audio and ipod auido. When I try to run my application I am getting an error like,

ld: framework not found AudioUnit
collect2: ld returned 1 exit status
Command /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/llvm-gcc-4.2 failed with exit code 1

my view controller code is as follows,

.h file:

 #import <UIKit/UIKit.h>
 #import <MediaPlayer/MediaPlayer.h>
 #import <AudioToolbox/AudioToolbox.h>
 #import <AVFoundation/AVFoundation.h>


 @interface AudioViewController : UIViewController     <AVAudioPlayerDelegate,MPMediaPickerControllerDelegate>
{
     UIButton *musicButton;
     UIButton *soundButton;
     AVAudioPlayer *audioPlayer;
     MPMusicPlayerController *musicPlayerController;
}
@property (nonatomic, retain)  UIButton *musicButton;
@property (nonatomic, retain)  UIButton *soundButton;
@property (nonatomic, retain) MPMusicPlayerController *musicPlayerController;

- (void)musicAction;
- (void)soundAction;

@end

.m File:

- (id)init {
    if ((self = [super init])) 
   {
         // Custom initialization
       }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];


    musicButton=[[UIButton alloc]initWithFrame:CGRectMake(10,250 ,100, 40)];
    musicButton.backgroundColor=[UIColor blueColor];
    [musicButton setTitle:@"Next" forState:UIControlStateNormal];
    [musicButton addTarget:self action:@selector(musicAction)   forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:musicButton];
    [musicButton release];

    soundButton=[[UIButton alloc]initWithFrame:CGRectMake(210,250 ,100, 40)];
    soundButton.backgroundColor=[UIColor blueColor];
    [soundButton setTitle:@"Pre" forState:UIControlStateNormal];
    [soundButton addTarget:self action:@selector(soundAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:soundButton];
    [soundButton release];

    //Setup our Audio Session
    OSStatus status = AudioSessionInitialize(NULL, NULL, NULL, NULL);    
    //We want our audio to play if the screen is locked or the mute switch is on
    UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
    status = AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (sessionCategory), &sessionCategory);
    //We want our audio to mix with other app's audio
    UInt32 shouldMix = true;
    status = AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (shouldMix), &shouldMix);
    //Enable "ducking" of the iPod volume level while our sounds are playing
    UInt32 shouldDuck = true;
    AudioSessionSetProperty(kAudioSessionProperty_OtherMixableAudioShouldDuck, sizeof(shouldDuck), &shouldDuck);
    //Activate our audio session
    AudioSessionSetActive(YES);

    //Setup the Music Player to access the iPod music library
    self.musicPlayerController = [MPMusicPlayerController applicationMusicPlayer];
    [self.musicPlayerController setShuffleMode: MPMusicShuffleModeSongs];
    [self.musicPlayerController setRepeatMode: MPMusicRepeatModeNone];
    [self.musicPlayerController setQueueWithQuery:[MPMediaQuery songsQuery]];

    //Setup a AVAudioPlayer sound to overlay against the Music Player audio
    NSURL *soundURL = [NSURL URLWithString:[[NSBundle mainBundle] pathForResource:@"overlay" ofType:@"mp3"]];
    NSError *error = nil;
    audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error: &error];
    if (!audioPlayer)
    {
        NSLog(@"Could not create audio effect player: %@", [error localizedDescription]);
    }
    [audioPlayer prepareToPlay];
}



- (void)musicAction
{
    if (self.musicPlayerController.playbackState == MPMusicPlaybackStatePlaying)
    {
        [self.musicPlayerController pause];
    }
    else if (self.musicPlayerController.playbackState == MPMusicPlaybackStateStopped
         || self.musicPlayerController.playbackState == MPMusicPlaybackStatePaused)
    {
        [self.musicPlayerController play];
    }
}
- (void)soundAction
{
    if (audioPlayer.playing)
    {
        [audioPlayer pause];
    }
    else
    {
        [audioPlayer play];
    }

}
- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}



- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

FrameWorks I am using,

1. AuidoUnit.framework.
2. AVFoundation.framework.
3. MediaPlayer.framework.
4. UIKit.framework.
5. Foundation.framework.
6. CoreGraphics.framework.
7. CoreData.framework.

Can you guys please take a look at it and let me know, what I am missing.

Thanks in advance, Chandra.

回答1:

In my case, by adding Accelerate.framework, besides the AudioToolbox.framework and CoreAudio.framework, the building succeeded. You may find this helpful as well.



回答2:

Try adding CoreAudio.framework and AudioToolbox.framework to your list of Frameworks.

And also remove AudioUnit.framework