AVFoundation库:声音无法播放

时间:2012-03-15 21:09:31

标签: cocoa

使用我的第二个应用程序...

当app移动到新图像时,按钮会转到单个图像。我想发声,但它不起作用......

在.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 个答案:

答案 0 :(得分:0)

您可以使用:

system("afplay path")