0
我有一個聲音,它在應用程序啓動時啓動,它的長度爲30秒。無論我在哪個視圖控制器中,如何在重播歌曲時重新播放歌曲?當應用程序啓動時,聲音應該再次啓動
我的代碼:
-(void)playBgMusic {
NSString *path = [[NSBundle mainBundle] pathForResource:@"bgmusic" ofType:@"aif"];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play]; }
-(id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if(self)
{
[self playBgMusic];
}
return self; }
謝謝,當我把它放在appdelegate中時出現錯誤,但它也在我的viewcontroller中工作 – Leon 2011-04-06 18:43:15