我將我的項目轉換爲ARC。 Xcode的代碼改變了這一行的例子不要播放聲音
soundFileURLRef = (CFURLRef) [tapSound retain];
到
soundFileURLRef = (__bridge CFURLRef) tapSound;
,但沒有播放聲音。怎麼了?
- (IBAction)buttonTapped:(UIButton *)sender {
// Create the URL for the source audio file. The URLForResource:withExtension: method is new in iOS 4.0
NSURL *tapSound = [[NSBundle mainBundle] URLForResource: @"abide" withExtension: @"aif"];
CFURLRef soundFileURLRef;
SystemSoundID soundFileObject;
// Store the URL as a CFURLRef instance
soundFileURLRef = (__bridge CFURLRef) tapSound; // I think this line is wrong
// Create a system sound object representing the sound file.
AudioServicesCreateSystemSoundID (
soundFileURLRef,
&soundFileObject
);
AudioServicesPlaySystemSound (soundFileObject);
}
我相信你的意思是說「只需在你的按鈕點擊方法中調用AudioServicesPlaySystemSound()」。不錯的寫作。 – NJones
@NJones:哎呀!感謝您的發現。 –