Working on my second app…
Have buttons going to individual images and when app moves to new image. I want to play sound, but its not working…
in .h file:
#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
in .m file:
#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
Any ideas? Trying to move from a controller via buttons to various pictures. Navigation works, but sounds do not play.
You can use: