- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
iOS开发之多媒体播放参考源码
OS sdk中提供了很多方便的方法来播放多媒体。本文将利用这些SDK做一个demo,来讲述一下如何使用它们来播放音频文件。AudioToolbox framework 使用AudioToolbox framework。这个框架可以将比较短的声音注册到 system sound服务上。被注册到system sound服务上的声音称之为 system sounds。它必须满足下面几个条件。1、?播放的时间不能超过30秒2、数据必须是 PCM或者IMA4流格式3、必须被打包成下面三个格式之一:Core Audio Format (.caf), Waveform audio (.wav),?或者 Audio Interchange File (.aiff) 声音文件必须放到设备的本地文件夹下面。通过AudioServicesCreateSystemSoundID方法注册这个声音文件,AudioServicesCreateSystemSoundID需要声音文件的url的CFURLRef对象。看下面注册代码:#import AudioToolbox/AudioToolbox.h@interface MediaPlayerViewController : UIViewController{ IBOutlet UIButton *audioButton; SystemSoundID shortSound;}- (id)init{ self = [super initWithNibName:@MediaPlayerViewController bundle:nil]; if (self) { // Get the full path of Sound12.aif NSString *soundPath = [[NSBundle mainBundle] pathForResource:@Sound12 ofType:@aif]; // If this file is actually in the bundle... if (soundPath) { // Create a file URL with this path NSURL *soundURL = [NSURL fileURLWithPath:soundPath]; // Register sound file located at that URL as a system sound OSStatus err = AudioServicesCreateSystemSoundID((CFURLRef)soundURL, shortSound); if (err != kAudioServicesNoError) NSLog(@Could not load %@, error code: %d, soundURL, err); } } return self; }这样就可以使用下面代码播放声音了:- (IBAction)playShortSound:(id)sender{ AudioServicesPlaySystemSound(shortSound);}使用下面代码,还加一个震动的效果:- (IBAction)playShortSound:(id)sender{ AudioServicesPlaySystemSound(shortSound); AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);}AVFoundation framework 对于压缩过Audio文件,或者超过30秒的音频文件,可以使用AVAudioPlayer类。这个类定义在AVFoundation framework中。 下面我们使用这个类播放一个mp3的音频文件。首先要引入AVFoundation framework,然后MediaPlayerViewController.h中添加下面代码:#import AVFoundation/AVFoundation.h@interface MediaPlayerViewController : UIViewController AVAudioPlayerDelegate{ IBOutlet UIButton *audioButton; SystemSoundID shortSound; AVAudioPlayer *audioPlayer; AVAudioPlayer类也是需要知道音频文件的路径,使用下面代码创建一个AVAudioPlayer实例:- (id)init{ self = [super initWithNibName:@MediaPlayerViewController bundle:nil]; if
您可能关注的文档
最近下载
- 人工智能教学课件.ppt VIP
- 公司与员工签订车辆使用协议(2024两篇) .pdf VIP
- 小森LS-40印刷机保养操作指导07.pdf VIP
- 2024-2025学年深圳市育才三中小升初入学分班考试语文试卷附答案解析.pdf VIP
- 咖啡瑞幸咖啡美国上市招股说明书中文全译版本.pdf
- 2023年深圳市南山区育才三中小升初分班考试数学模拟试卷及答案解析.pdf VIP
- 涵管埋设施工技术方案.docx VIP
- 2018-2019、2021-2022年重庆邮电大学《808数字电路与逻辑设计》历年硕士真题汇总.pdf VIP
- 初中化学装置气密性的检验.pptx VIP
- 原理1-经济学概述.ppt VIP
文档评论(0)