2011-12-05 213 views
0

我有兩個應用程序使用audiotoolbox框架播放短mp3文件。 部署目標是:4.0 而基本SDK是:iOS 5.0 SDKAudioToolBox不在某些設備上播放

我有iOS 5.0的iPhone 4和iOS 5.0的iPhone 3GS。他們兩個都在播放聲音。我的一位擁有iOS 4.3的iPad的朋友無法播放任何聲音。而另一位使用iOS 4.2的iPhone 4的朋友也無法播​​放這些聲音。它看起來像是與iOS的東西,但我真的不知道什麼是它不玩的真正原因。

下面是播放文件我的代碼示例:

H.文件(僅適用於相關的代碼):

#import <AudioToolbox/AudioToolbox.h> 

SystemSoundID soundID1; 

M.文件(僅適用於相關的代碼):

@synthesize soundID1 

- (IBAction)one:(id)sender 
{ NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"mp3"]; 
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID1); 
    AudioServicesPlaySystemSound (soundID1); 
} 

- (void)dealloc { AudioServicesDisposeSystemSoundID (self.soundID1);} 
+0

編輯:我是新手,所以如果我犯了一些瘋狂的錯誤,請原諒我。此外,我不確定我在這裏使用了audiotoolbox,但仍在尋找解決方案。 –

回答

1

爲什麼不使用AVAudioPlayer播放聲音文件。

這是代碼。

#import <AVFoundation/AVAudioPlayer.h> 

- (void)viewDidLoad 
{ 

    NSString *path1 = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"mp3"]; 
    1 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path1] error:NULL]; 
    1.delegate = self; 
    [1 setVolume:1.0]; 
    [1 prepareToPlay]; 

} 

- (IBAction)one:(id)sender 
{ 

    if (1 && 1.playing) { 
     [1 stop]; 
     [1 setCurrentTime:0]; 
     [1 play]; 
    }else { 
     [1 play]; 
    } 

} 

自iOS 5使用ARC以後,不需要發佈。但是,如果您使用較舊的iOS,那麼在dealloc方法上創建一個發行版。

相關問題