2010-12-07 103 views
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]; 
} 

但在这个时候我的应用程序终止有人可以告诉我这是什么问题?

+1

你有没有`#import` -ed`BackgroundMusic.h`? – 2010-12-07 05:06:19

+0

当您的应用程序终止时,您收到的错误消息是什么? `EXC_BAD_ACCESS`? `NSException`?还有别的吗? – 2010-12-07 05:17:42

回答

0

你得到的错误信息是什么?当应用程序终止时,您可以在gdb窗口中检查。它会显示正确的错误信息。在该线程中发布该错误消息。

相关问题