1
我有一个avaudioplayer加载一个声音文件和循环。问题是,每次文件循环时,都会有暂停/延迟,这会使音乐听起来很糟糕。ios删除avaudioplayer循环延迟
我发现这个问题有类似的问题,但是为2个球员。我有一个具有在每个循环1秒的暂停单人游戏:AVAudioPlayer eliminating one second pause between sound files
这里是我的音频播放器的设置是什么样子:
@interface HomeViewController()
@property (strong, nonatomic) DataController *dataController;
@end
@implementation HomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.dataController = [DataController sharedInstance];
[self createAndStartAudioPlayer];
}
- (void) viewWillAppear:(BOOL)animated{
[self.dataController.player play];
}
- (void) createAndStartAudioPlayer {
NSTimeInterval shortStartDelay = 0.01; // seconds
NSTimeInterval now = self.dataController.player.deviceCurrentTime;
[self.dataController.player playAtTime: now + shortStartDelay];
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"jingle-loop" ofType:@"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
self.dataController.player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL fileTypeHint:AVFileTypeMPEGLayer3 error:nil];
self.dataController.player.numberOfLoops = -1; //infinite
[self.dataController.player prepareToPlay];
}
如何停止该暂停1秒和播放喜欢的环这是一首连续的歌曲?
第一次播放文件时,是否有延迟? –
如果第一次播放文件时出现延迟,请尝试使用音频编辑器(如audacity)编辑音频文件,并在实际音频前后移除空白区域。有时候会在音频中添加淡入或淡出样式文件。看看它是否有效。 –