Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5407201
  • 博文数量: 763
  • 博客积分: 12108
  • 博客等级: 上将
  • 技术积分: 15717
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-28 21:21
个人简介

业精于勤,荒于嬉

文章分类

全部博文(763)

文章存档

2018年(6)

2017年(15)

2016年(2)

2015年(31)

2014年(14)

2013年(87)

2012年(75)

2011年(94)

2010年(190)

2009年(38)

2008年(183)

2007年(28)

分类: C/C++

2010-07-16 11:17:56

有时候在 iPhone 游戏中,既要播放背景音乐,同时又要播放比如枪的开火音效。此时您可以试试以下方法 NSString *musicFilePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@wav]; //创建音乐文

有时候在 iPhone 游戏中,既要播放背景音乐,同时又要播放比如枪的开火音效。此时您可以试试以下方法

    NSString *musicFilePath = [[NSBundle mainBundle] pathForResource:fileName ofType:@"wav"];       //创建音乐文件路径
    NSURL *musicURL = [[NSURL alloc] initFileURLWithPath:musicFilePath];  
    AVAudioPlayer* musicPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:musicURL error:nil];
    [musicURL release];
    [musicPlayer prepareToPlay];
    //[musicPlayer setVolume:1];            //设置音量大小
    //musicPlayer .numberOfLoops = -1;//设置音乐播放次数  -1为一直循环

要导入框架 AVFoundation.framework,头文件中 #import ;做成类的话则更方便。

阅读(1548) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~