小编mam*_*aml的帖子

当我暂停AVAudioPlayer时,为什么锁屏音频控件会消失?

我正在使用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)

audio objective-c avaudioplayer ios uievent

17
推荐指数
1
解决办法
6718
查看次数

标签 统计

audio ×1

avaudioplayer ×1

ios ×1

objective-c ×1

uievent ×1