2012-03-15 65 views
0

處理我的第二個應用程序...AVFoundation庫:聲音不會播放

讓按鈕進入單個圖像,當應用程序移動到新圖像時。我想播放聲音,但它不工作...

在.h文件中:

#import <UIKit/UIKit.h> 

#import <AVFoundation/AVFoundation.h> 

#import "SoundController.h" 

@interface BoatController : UIViewController { 

} 

@property (nonatomic, retain) UIView *Cruise_Ship; 

@property (nonatomic, retain) UIView *Speed_Boat; 

@end 

在.m文件:

#import "BoatController.h" 

@implementation BoatController 

@synthesize Cruise_Ship; 

@synthesize Speed_Boat; 

- (void)viewDidLoad { 
[super viewDidLoad]; 

} 

-(void)View01 
{ 
    UIView * containingView = Cruise_Ship; 
    [self.view removeFromSuperview]; 
    [containingView addSubview:Cruise_Ship]; 
    CFBundleRef mainBundle = CFBundleGetMainBundle(); 
    CFURLRef soundFileURLRef; 
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"boathorn01",CFSTR ("wav"), NULL); 
    SystemSoundID soundID; 
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID); 
    AudioServicesPlaySystemSound(soundID); 
} 

-(void)View2 
{ 
    UIView * containingView = Speed_Boat.superview; 
    [self.view removeFromSuperview]; 
    [containingView addSubview:Speed_Boat];  
    CFBundleRef mainBundle = CFBundleGetMainBundle(); 
    CFURLRef soundFileURLRef; 
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"nautical010",CFSTR ("wav"), NULL);  
    SystemSoundID soundID; 
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID); 
    AudioServicesPlaySystemSound(soundID); 
} 

@end 

任何想法?嘗試通過按鈕從控制器移動到各種圖片。導航有效,但聲音不起作用。

+1

重新標記,因爲這不是一個Xcode的問題。你的問題涉及Cocoa框架。 – Almo 2012-03-15 21:11:38

回答

0

您可以使用:

system("afplay path")