gpt4 book ai didi

iphone - IOS播放短促的声音

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:31:25 32 4
gpt4 key购买 nike

我正在尝试在我的 iPhone 应用程序中播放短促的警报声我正在使用我找到的这段代码,但它不会播放任何声音。

NSString *toneFilename = [[NSBundle mainBundle] pathForResource:@"alarm" ofType:@"wav"];
NSURL *toneURLRef = [NSURL fileURLWithPath:toneFilename];
SystemSoundID Sound;

AudioServicesCreateSystemSoundID(
(__bridge CFURLRef) toneURLRef,
&camerSound
);

AudioServicesPlaySystemSound(Sound);

当我尝试使振动起作用时:

AudioServicesPlayAlertSound(kSystemSoundID_Vibrate);

谢谢

最佳答案

使用 AVFoundationFramework

AVFoundation.framework 添加到项目中。

#import <AVFoundation/AVFoundation.h>

NSString *toneFilename = [[NSBundle mainBundle] pathForResource:@"alarm" ofType:@"wav"];
NSURL *toneURLRef = [NSURL fileURLWithPath:toneFilename];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL: toneURLRef error: nil];
player.currentTime = 0;
player.volume = 1.0f;
[player play];

关于iphone - IOS播放短促的声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13788534/

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