iPhone:AVAudioPlayer支持.wav格式吗?

时间:2011-09-12 06:49:54

标签: iphone objective-c ios4 avaudioplayer

我将在我的应用中使用.wav音频文件。

AVAudioPlayer是否支持.wav文件格式?

AVAudioPlayer支持哪些其他格式?

2 个答案:

答案 0 :(得分:3)

是的,AVAudioPlayer可让您播放.wav个文件。

这很直接:

// in the corresponding .h file:
// @property (nonatomic, retain) AVAudioPlayer *player;

// in the .m file:
@synthesize player; // the player object

NSString *soundFilePath =
            [[NSBundle mainBundle] pathForResource: @"sound"
                                            ofType: @"wav"];

NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];

AVAudioPlayer *newPlayer =
            [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL
                                                   error: nil];
[fileURL release];

self.player = newPlayer;
[newPlayer release];

[player prepareToPlay];

来自:Playing Sounds Easily with the AVAudioPlayer Class

答案 1 :(得分:0)

您可以在此处找到有关您问题的完整答案:MultimediaPG

音频播放和录制格式 iPhone OS支持的音频播放格式如下:

*AAC
*HE-AAC
*AMR (Adaptive Multi-Rate, a format for speech)
*ALAC (Apple Lossless)
*iLBC (internet Low Bitrate Codec, another format for speech)
*IMA4 (IMA/ADPCM)
*linear PCM (uncompressed)
*µ-law and a-law
*MP3 (MPEG-1 audio layer 3

iPhone OS支持的录音格式如下:

*AAC (on supported devices only)
*ALAC (Apple Lossless)
*iLBC (internet Low Bitrate Codec, for speech)
*IMA4 (IMA/ADPCM)
*linear PCM
*µ-law and a-law