簡體   English   中英

應用加載時播放聲音

[英]Playing sound when app loads

嘗試在應用加載時播放聲音

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    //sleep(2);
    [NSThread sleepForTimeInterval:2.0];

    CFBundleRef mainBundle = CFBundleGetMainBundle();
    CFURLRef soundFileURLRef;
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"austinpowers", CFSTR("wav"), NULL); 

    if (soundFileURLRef) {
        CFStringRef url = CFURLGetString(soundFileURLRef);
    }
    UInt32 soundID;
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    AudioServicesPlaySystemSound(soundID);



    // Override point for customization after application launch.

    // Add the view controller's view to the window and display.
    [self.window addSubview:viewController.view];
    [self.window makeKeyAndVisible];

    return YES;
}

它會播放聲音,但僅在加載牆紙(default.png)消失時才播放。 如果有人可以幫助我,或為我指明正確的方向

謝謝

不要使用Default.png,而是創建您的自定義啟動屏幕視圖控制器,您可以在其中顯示圖像並播放聲音。

通過在AppDelegate.m文件中執行以下操作為我解決了此問題

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions {

   NSURL *clip = [[NSBundle mainBundle] URLForResource: @"intro" withExtension:@"caf"];
   self.startupPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:clip error:NULL];
   [self.startupPlayer play]; 

}

這也可能對您有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM