小编zer*_*mat的帖子

Xcode在prepareToPlay上停止

使用AVAudioPlayer将声音添加到工作应用程序,它会在prepareToPlay上停止/挂起.请注意,它也会停止/挂起.点击"继续执行程序"几次会使应用程序恢复.只有在模拟器中运行程序时才会出现此问题.

使用Xcode 4.6

代码片段:

ViewController.h

#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface ViewController : UIViewController <AVAudioPlayerDelegate>

@end
Run Code Online (Sandbox Code Playgroud)

ViewController.m

#import "ViewController.h"

@interface ViewController ()
{
}

@property (nonatomic, strong) AVAudioPlayer *audioPlayer;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self initilizeAudio];
}

- (void)initilizeAudio
{
    NSError *error = nil;
    NSURL *audioURL = [[NSBundle mainBundle] URLForResource:@"Background" withExtension:@"mp3"];

    self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioURL error:&error];
    if (error)
    {
        NSLog(@"Error in audioPlayer: %@", [error localizedDescription]);
    }
    else
    {
        [self.audioPlayer setDelegate:self];
        [self.audioPlayer prepareToPlay];
    }
}

@end
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪

0 …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c avaudioplayer

21
推荐指数
1
解决办法
3886
查看次数

标签 统计

avaudioplayer ×1

objective-c ×1

xcode ×1