0
我使用下面的代碼:我的聲音被放置在MYAPP /共享資源/ background_music.aiff沒有背景音樂,而在玩的Xcode 4.2
@synthesize window = _window;
- (void)dealloc
{
[backgroundSound release];
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
sleep(3);
//this variable can be named differently
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/background_music.aiff",[[NSBundle mainBundle] resourcePath]]];
NSError *error;
backgroundSound = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
backgroundSound.numberOfLoops = -1;
//>> this will allow the file to //play an infinite number of times */
return YES;
}
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
AVAudioPlayer *backgroundSound;
}
@property (strong, nonatomic) UIWindow *window;
@end
有沒有錯誤,也沒有循環sound.Kindly告訴我發生了什麼事。
問候
沒事做的問題,但在'didFinishLaunchingWithOptions'中使用'sleep(3)'會導致一些很大的問題。因爲如果你的應用程序啓動不夠快,iOS將會終止它。使用'default.png'覆蓋rootviewcontroller並在應用程序完全加載時將其刪除。 – rckoenes
@NSPostWhenIdle沒有聲音 –
記錄聲音的URL返回正確嗎? –