2011-06-24 50 views
1

我正在實施一個基於音頻的應用程序,因爲我需要同時播放應用程序音頻和iPod音頻。當我嘗試運行我的應用程序,我得到一個錯誤一樣,未找到AudioUnit框架

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 

我的視圖控制器代碼如下,

.h文件中:

#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文件:

- (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,

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

你們可以請看看它,讓我知道,我失蹤了。

在此先感謝, 錢德拉。

回答

0

在我的情況下,通過增加Accelerate.framework,除了AudioToolbox.framework和CoreAudio.framework,建設成功。您也可以找到this

3

嘗試將CoreAudio.frameworkAudioToolbox.framework添加到框架列表中。

而且還刪除AudioUnit.framework

+0

對我來說,這沒有奏效。我也有AudioUnit.framework。事實上,如果我刪除這些框架中的任何一個,我會遇到很多鏈接錯誤。但是,如果我有他們三個,我會得到一個鏈接錯誤'框架未找到AudioUnit'。任何想法我做錯了什麼?任何人都明白爲什麼這個錯誤首先出現? – Emmanuel

+0

@Emmanuel您開發的iOS SDK版本是什麼? –

+0

我正在使用Xcode 4.2.1編譯SDK 4.3。也就是說,我通過添加一些庫來擺脫這個問題。不確定哪一個導致問題消失。 – Emmanuel