gpt4 book ai didi

ios - 在iPhone iOS中播放简单的WAV文件

转载 作者:行者123 更新时间:2023-12-03 02:10:50 28 4
gpt4 key购买 nike

我正在尝试使用AudioToolBox框架单击一个按钮来播放wav文件。没有引发任何错误,但声音没有播放。

-(IBAction)buttonPressed
{

NSString *path;
NSURL *url;
AVAudioPlayer *player;
NSLog(@"Hai");
path = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"];
url=[NSURL fileURLWithPath:path];
player=[[AVAudioPlayer alloc]initWithContentsOfURL:url error:NULL];
[player setVolume:5.0];
[player play];
}

也尝试过此代码
NSString *path = [NSString stringWithFormat:@"%@%@", [[NSBundle mainBundle] resourcePath], @"censor-beep-01.wav"];

SystemSoundID soundID;
NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO];
//Use audio sevices to create the sound
AudioServicesCreateSystemSoundID((__bridge CFURLRef)filePath, &soundID);
//Use audio services to play the sound
AudioServicesPlaySystemSound(soundID);

最佳答案

在头文件中设置AVAudioPlayer框架。并声明AVAudioPlayer * player;在.h文件中

@property(非原子的,保留)AVAudioPlayer * player;
在按钮 Action AVAudioPlayer * player中合成并删除此行;
您应该在.h文件中声明。

关于ios - 在iPhone iOS中播放简单的WAV文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24320528/

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