gpt4 book ai didi

ios - 如何在 Xcode 的 AppDelegate 下创建一个循环?

转载 作者:行者123 更新时间:2023-11-29 02:15:18 24 4
gpt4 key购买 nike

这是我在 AppDelegate.m 下的代码

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

NSLog(@"PLAY SOUND CLIP WHILE LOADING APP");
NSURL *clip = [[NSBundle mainBundle] URLForResource: @"project" withExtension:@"m4a"];
self.startipPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:clip error:NULL];
[self.startipPlayer play]
}

这只播放音频一次,不重复。如何让这段代码重复本身或至少重复这首歌?

或者任何创建播放背景音乐而不是循环播放的替代方法都会有所帮助。谢谢。

最佳答案

查看 documentation for AVAudioPlayer ,它似乎具有 numberOfLoops 属性,如果将其设置为负数,则会无限期地重复这首歌,直到您调用停止。

可能是这样的(未经测试):

NSURL *clip = [[NSBundle mainBundle] URLForResource: @"project" withExtension:@"m4a"];
self.startipPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:clip error:NULL];
startipPlayer.numberOfLoops = -1
[self.startipPlayer play]

关于ios - 如何在 Xcode 的 AppDelegate 下创建一个循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28822784/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com