gpt4 book ai didi

ios - 在我的应用程序中播放声音后如何在 xcode 中重新启动音乐播放器

转载 作者:行者123 更新时间:2023-11-29 03:20:11 25 4
gpt4 key购买 nike

使用 AVAudioPlayer 播放声音时,后台音乐播放器停止,当我的声音结束时,音乐播放器未恢复,我如何恢复音乐播放器?

最佳答案

#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

关于ios - 在我的应用程序中播放声音后如何在 xcode 中重新启动音乐播放器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21202700/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com