gpt4 book ai didi

ios - 单击按钮时未播放音频

转载 作者:行者123 更新时间:2023-12-01 20:05:35 25 4
gpt4 key购买 nike

我想在Button单击上播放音频。我已经尝试过此代码,但是音频无法播放:-

NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithData:soundFileURL error:nil];
audioPlayer.delegate = self;
audioPlayer.volume=1.0;
[audioPlayer setNumberOfLoops:1];
[audioPlayer play];

最佳答案

您尚未创建播放器项目

//在.h文件中声明

AVPlayerItem *playerItem;

//然后在.m文件中
player = [AVPlayer playerWithPlayerItem:playerItem];

之后播放
   [player play];

关于ios - 单击按钮时未播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38966793/

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