iPhone上的系统声音无法播放 [英] system sound on iphone not playing

查看:88
本文介绍了iPhone上的系统声音无法播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想播放系统声音,但什么也没听到:

I want to play a system sound but I don't hear anything:

- (void) play_system_sound
{
    NSLog(@"Play system sound");

    SystemSoundID soundID;
    NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@"Tock" ofType:@"aiff"];
    NSLog(@"path = %@", path );
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);
    AudioServicesPlaySystemSound(soundID);
    AudioServicesDisposeSystemSoundID(soundID);
    NSLog(@"Play system sound DONE");
}

我什么也没听到.我在做什么错了?

I don't hear anything. What am I doing wrong?

推荐答案

AudioServicesPlaySystemSound(soundID)之后,请勿立即调用AudioServicesDisposeSystemSoundID(soundID).

After AudioServicesPlaySystemSound(soundID) ,don't call AudioServicesDisposeSystemSoundID(soundID) immediately.

尝试一下:

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSString *path = [[NSBundle bundleWithIdentifier:@"com.apple.UIKit"] pathForResource:@"Tock" ofType:@"aiff"];
    AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:path], &soundID);
}

-(void)dealloc
{ 
    AudioServicesDisposeSystemSoundID(soundID);
}

- (void)play_system_sound
{
    AudioServicesPlaySystemSound(soundID);
}

这篇关于iPhone上的系统声音无法播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆