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