声音在iOS中不打 [英] Sound Not Playing in iOS

查看:129
本文介绍了声音在iOS中不打的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出一个小的iOS游戏,并完成了一切,除了声音。我检查了文件格式,试图.WAV和.AIFF,其中没有工作。相关code是如下:

I am making a small iOS game, and have finished everything, except the sound. I have checked the file formats, tried .wav and .aiff and none of them work. The related code is as follows:

.H 文件:

#import <AudioToolbox/AudioToolbox.h>

@public SystemSoundID mBeep;
NSString* path;
NSURL* url;

.M 文件:

path = [[NSBundle mainBundle]pathForResource:@"hit" ofType:@"wav"];
url = [NSURL URLWithString:path];
AudioServicesCreateSystemSoundID((CFURLRef)url, &mBeep);

AudioServicesPlaySystemSound(mBeep); //Gets called, doesn't play

如果我使用无证ID之一,如 1103 AudioServicesPlaySystemSound ,声音正常播放。

If I use one of the undocumented ids, like 1103 with AudioServicesPlaySystemSound, that sound plays fine.

我敢肯定我的文件都很好,因为同一个.wav文件完美的作品在Android上,VLC时,iTunes等。

I am quite sure my files are fine, as the same .wav file works perfectly on Android, VLC, iTunes etc.

有谁知道我做错了?

推荐答案

最有可能的罪魁祸首是对WAV编码。作为this回答,iOS版仅支持某些codeCS,和你想大概玩WAV使用不支持的。

The most likely culprit is the encoding on the WAV. As indicated in this answer, iOS only supports certain codecs, and the WAV you're trying to play probably uses an unsupported one.

像这样回答说,最简单的解决方法是将使用命令行 afconvert 工具(无损)您的WAV转换成苹果的默认CAF格式,并使用它

Like that answer says, the easiest solution will be to use the command-line afconvert tool to (losslessly) convert your WAV to Apple's default CAF format and use that instead:

afconvert sound1.wav sound1.caf

另一种可能性和实际问题的任择议定书有-是该文件不存在和/或 pathForResource 没有成功找到它,这将指示通过路径

Another possibility—and the actual problem the OP had—is that the file doesn't exist and/or pathForResource isn't successfully finding it, which would be indicated by path being nil.

这篇关于声音在iOS中不打的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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