0
我有一个命名为Backgroundmusic.h文件类是如何调用另一个类中定义的方法
#import "UIKit/UIKit.h"
#import "AVFoundation/AVFoundation.h"
#import "AudioToolbox/AudioToolbox.h"
@interface Backgroundmusic : NSObject{
}
-(void)playBgmusic:(BOOL) issoundon;
@end
Backgroundmusic.m是
-(void)playBgmusic:(BOOL)issoundon {
//AVAudioPlayer *myExampleSound; //this variable can be named differently
if (issoundon==TRUE) {
NSString *path =[[NSBundle mainBundle] pathForResource:"bg" ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef) [NSURL fileURLWithPath:path]
,&soundID);
AudioServicesPlaySystemSound(soundID);
}
else {
NSString *path =[[NSBundle mainBundle] pathForResource:nil ofType:@"wav"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((CFURLRef) [NSURL fileURLWithPath:path]
,&soundID);
AudioServicesPlaySystemSound(soundID);
}
}
基本上什么,我试图做的是设置背景音乐到我的应用程序在开始时,并允许用户在中间停止它 所以在我的xAppdelegate.mi称这个功能为
- (void)applicationDidFinishLaunching:(UIApplication *)application {
Backgroundmusic *bgm=[[Backgroundmusic alloc] init];
[bgm playBgmusic:TRUE];
}
但在这个时候我的应用程序终止有人可以告诉我这是什么问题?
你有没有`#import` -ed`BackgroundMusic.h`? – 2010-12-07 05:06:19
当您的应用程序终止时,您收到的错误消息是什么? `EXC_BAD_ACCESS`? `NSException`?还有别的吗? – 2010-12-07 05:17:42