2013-01-12 38 views
0

我有一個非常類似的問題,喜歡這裏:link 在ViewController.h文件添加此:創建SystemSoundID失敗的iOS - OSStatus = 0

#import <UIKit/UIKit.h> 
#include <AudioToolbox/AudioToolbox.h> 

@interface ViewController : UIViewController 
@property SystemSoundID outSystemSoundID1; 
@end 

和ViewController.m是:

#import <ViewController.h> 
@interface ViewController() 
- (IBAction)playtrack; 


@end 

@implementation ViewController 

@synthesize outSystemSoundID1; 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 

NSString *path1 = [[NSBundle mainBundle] pathForResource:@"1000Hz-0-4sec" ofType:@"wav"]; 
NSURL *url1 = [NSURL fileURLWithPath:path1]; 
//CFURLRef lol = (CFURLRef)objc_unretainedPointer(url1); 
//AudioServicesCreateSystemSoundID(lol, &outSystemSoundID1); 
OSStatus status = AudioServicesCreateSystemSoundID((__bridge CFURLRef)url1, &outSystemSoundID1); 
NSLog(@"AudioServicesCreateSystemSoundID status = %ld", status); 
} 

- (IBAction)playtrack { 
AudioServicesPlaySystemSound (outSystemSoundID1); 
} 
@end 

我想播放的聲音文件位於支持文件下。

的OSStatus說:

AudioServicesCreateSystemSoundID狀態= 0

我試過了CFURLRef很多不同的組合就像你可以在出評論的部分看。

也許我的文件不被支持?在我得到解決方案後,我想用這種方法初始化aif格式的3個聲音文件。

希望你能幫幫我!謝謝:)

我有ARC激活,我在iOS 6.0.1(iPhone)

回答

3

OSStatus = 0意味着 「沒有錯誤」,這意味着該函數AudioServicesCreateSystemSoundID成功

+0

但是爲什麼當我按下按鈕時(這是連接到 - (IBAction)playtrack),應用程序會一直崩潰? 我是否需要將「(id)發送者」添加到此方法中? – mrlowalowa

+0

@mrlowalowa:應用程序崩潰時是否收到任何錯誤消息? –

+0

我得到了一些指向autorelease主 但我有一個不同的IBAction在這個ViewControll.C文件中運行。我把它與另一個按鈕放在一起,我聽到了聲音... 我創建了3個正常工作的其他方法,但它們不受不同按鈕左右的約束。 也許它超載,如果我有那裏2個不同的IBActions .. – mrlowalowa