AVAudioPlayer播放没有声音

来源:互联网 发布:linux mongbd部署 编辑:程序博客网 时间:2024/04/29 06:43
在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions中加入这句话    [[AVAudioSession sharedInstance]setCategory:AVAudioSessionCategoryPlayback error:nil];

- (void)viewDidLoad{    [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib.       NSString * resourcePath = [[NSBundle mainBundle] pathForResource:@"SIMS_BreathingSpace_100215" ofType:@"mp3"];//    NSString * resourcePath = [[NSBundle mainBundle] pathForResource:@"time" ofType:@"mp3"];    //    NSString * resourcePath = [[NSBundle mainBundle] pathForResource:@"time" ofType:@"mp3"];    NSData  *data =[NSData dataWithContentsOfFile:resourcePath];    audioPlayer = [[AVAudioPlayer alloc]initWithData:data error:nil];    audioPlayer.delegate = self;    audioPlayer.volume = 0.8f;    [audioPlayer prepareToPlay];    }-(IBAction)play:(id)sender{    [audioPlayer play];}



stackover上有解释,看的不大懂http://stackoverflow.com/questions/4640880/mp3-playing-using-avaudioplayer-not-working-on-device点击打开链接


0 0
原创粉丝点击