我正在使用 AVAudioPlayer 播放音频文件,但它在某些设备上无法播放,我该如何解决我的问题
if(_defaultSettings)
{
_soundFilePath = [[NSBundle mainBundle] pathForResource:@"ring" ofType:@"wav"];
NSLog(@"ringTone Path%@",_soundFilePath);
// /System/Library/Audio/UISounds/
_audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:_soundFilePath ]error:nil];
[_audioPlayer prepareToPlay];
[_audioPlayer play];
_audioPlayer.numberOfLoops = -1;
AudioServicesPlaySystemSound(1000);
}
- (void)playSystemSound {
NSLog(@"playSystemSound");
// Create the URL for the source audio file. The URLForResource:withExtension: method is
// new in iOS 4.0.
NSURL *tapSound = [[NSBundle mainBundle] URLForResource: @"short_low_high"
withExtension: @"wav"];
if (!self._soundFileURLRef) {
// Store the URL as a CFURLRef instance
self._soundFileURLRef = (CFURLRef) [tapSound retain];
// Create a system sound object representing the sound file.
AudioServicesCreateSystemSoundID (_soundFileURLRef, &_soundFileObject);
}
// Play the sound
AudioServicesPlaySystemSound (_soundFileObject);
// // to vibrate the device // AudioServicesPlaySystemSound (kSystemSoundID_Vibrate);
}