Slow start for AVAudioPlayer the first time a sound is played

我们编写app程序的时候经常需要播放一些声音效果

但是这些声音在播放第一次的时候会造成程序卡顿, 因为在初始化, 从而引起不好的用户体验

可以用 [theAudio prepareToPlay];   来初始化音乐的播放,这样就能避免第一次播放时程序的卡顿了

NSString *path = [[NSBundle mainBundle] pathForResource:@"bubble-pop" ofType:@"mp3"];
    theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
    theAudio.delegate = self;
    theAudio.numberOfLoops = 0;
    [theAudio prepareToPlay];
    

猜你喜欢

转载自dsr-22.iteye.com/blog/2199672