我有两个应用程序使用音频工具箱框架来播放简短的mp3文件。部署目标是: 4.0,Base是: iOS 5.0SDK
我有iPhone4和iOS 5.0,iphone 3GS和iOS 5.0。他们俩都在播放声音。我的一个朋友,有iPad与iOS 4.3,不能播放任何声音。另一个有iPhone 4和iOS 4.2的朋友也不能播放这些声音。它看起来像是与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);}发布于 2011-12-05 14:18:35
为什么不使用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方法上创建一个发行版。
https://stackoverflow.com/questions/8380216
复制相似问题