У меня есть класс с именем 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];
}
, но в настоящее время мое приложение завершается, может кто-нибудь сказать мне, в чем проблемаздесь ???