使用AVAudioPlayer播放我的声音时,后台的音乐播放器停止,当我的声音结束时,音乐播放器没有恢复,我如何恢复音乐播放器?
发布于 2014-05-07 16:10:53
#import "ViewController.h"
#import <AVFoundation/AVFoundation.h>
@interface ViewController () <AVAudioPlayerDelegate>
@property (nonatomic, strong) AVAudioPlayer *audioPlayer;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"ttt" ofType:@"mp3"]] error:nil];
_audioPlayer.delegate = self;
}
- (void)play:(id)sender
{
[_audioPlayer play];
}
- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *error = nil;
if (![audioSession setActive:NO withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error]) {
NSLog(@"resume music player failed, error=%@", error);
}
}
@end
https://stackoverflow.com/questions/21202700
复制相似问题