gpt4 book ai didi

ios - 应用音频未播放

转载 作者:行者123 更新时间:2023-12-03 02:33:59 26 4
gpt4 key购买 nike

因此,在我的文件中,我有以下代码,目的是在后台播放音乐文件:

-(void) BackGroundMusic {
NSString *soundPath = [[NSBundle mainBundle]pathForResource:@"LostInTheSea" ofType:@"mp3"];
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);
AudioServicesPlaySystemSound(soundID);
}

然后在 View 中加载部分我有:
[self BackGroundMusic];

我添加了所有工具箱,例如AVFoundation和AudioToolbox,但是我听不到任何音频播放。请帮忙 !

最佳答案

您不应该按照user523234的说明使用系统声音来播放mp3文件。
请改用AVAudioPlayer。这是一个无限循环的示例:

#import "AVFoundation/AVAudioPlayer.h"
#import "AVFoundation/AVAudioSession.h"

-(void)playbgMusic {
AVAudioPlayer *soundbgMusic;
NSString *soundPath;
soundPath= [[NSBundle mainBundle] pathForResource:@"bgMusic" ofType:@"mp3"];
soundbgMusic = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:soundPath] error:NULL];
soundbgMusic.volume = 1.0;
soundbgMusic.numberOfLoops = -1;
[soundbgMusic prepareToPlay];
soundbgMusic.currentTime = 0.0;
[soundbgMusic play];
}

关于ios - 应用音频未播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28010398/

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