我正在使用AVAudioPlayer的一个实例来播放音频文件.该应用程序配置为在后台播放音频,并设置适当的音频会话.我也成功接收了遥控事件.
这是代码:
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController ()
@property (nonatomic) AVAudioPlayer *player;
@end
@implementation ViewController
@synthesize player;
- (BOOL)canBecomeFirstResponder { return YES; }
- (void)viewDidLoad
{
[super viewDidLoad];
// Turn on remote control event delivery
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
// Set ourselves as the first responder
[self becomeFirstResponder];
// Set the audio session
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
BOOL success = [audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
NSError *activationError = nil;
success = [audioSession setActive:YES error:&activationError];
// Play an …Run Code Online (Sandbox Code Playgroud)