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
任何想法?尝试通过按钮从控制器移动到各种图片。导航有效,但声音不起作用。
重新标记,因为这不是一个Xcode的问题。你的问题涉及Cocoa框架。 – Almo 2012-03-15 21:11:38