gpt4 book ai didi

ios - 在后台 ios 应用程序中播放音乐

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

在我的代码中:

- (void) viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"www/media/BlueZedEx" ofType:@"mp3"]];

AVAudioPlayer *click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];

NSLog(@"goldenace launchOptions = %@", musicFile);
click.delegate = self;
click.numberOfLoops = -1;
[click play];

}

但是当我在模拟器中运行我的应用程序时没有音乐播放。请帮忙!

最佳答案

使用它来播放背景音频:

 [[AVAudioSession sharedInstance] setDelegate: self];
NSError *setCategoryError = nil;
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: &setCategoryError];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

引用这个link

关于ios - 在后台 ios 应用程序中播放音乐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16494064/

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