iOS开发 - 播放系统音效、自定义音效
2012-08-27 17:01
561 查看
播放系统音效、自定义音效工具类
需求大致分为三种:
1.震动
2.系统音效(无需提供音频文件)
3.自定义音效(需提供音频文件)
我的工具类的封装:
调用方法步骤:
1.加入AudioToolbox.framework到工程中
2.调用WQPlaySound工具类
需求大致分为三种:
1.震动
2.系统音效(无需提供音频文件)
3.自定义音效(需提供音频文件)
我的工具类的封装:
01 | // |
02 | // WQPlaySound.h |
03 | // WQSound |
04 | // |
05 | // Createdby念茜on12-7-20. |
06 | // Copyright(c)2012年__MyCompanyName__.Allrightsreserved. |
07 | // |
08 |
09 | #import <UIKit/UIKit.h> |
10 | #import <AudioToolbox/AudioToolbox.h> |
11 |
12 | @interface WQPlaySound:NSObject |
13 | { |
14 | SystemSoundID soundID; |
15 | } |
16 |
17 | /** |
18 | * |
19 | * |
20 | * |
21 | */ |
22 | -(id)initForPlayingVibrate; |
23 |
24 | /** |
25 | * |
26 | * |
27 | * |
28 | * |
29 | * |
30 | * |
31 | */ |
32 | -(id)initForPlayingSystemSoundEffectWith:(NSString |
33 |
34 | /** |
35 | * |
36 | * |
37 | * |
38 | * |
39 | * |
40 | */ |
41 | -(id)initForPlayingSoundEffectWith:(NSString *)filename; |
42 |
43 | /** |
44 | * |
45 | */ |
46 | -( void )play; |
47 |
48 | @end |
01 | // |
02 | // WQPlaySound.m |
03 | // WQSound |
04 | // |
05 | // Createdby念茜on12-7-20. |
06 | // Copyright(c)2012年__MyCompanyName__.Allrightsreserved. |
07 | // |
08 |
09 | #import "WQPlaySound.h" |
10 |
11 | @implementation WQPlaySound |
12 |
13 | -(id)initForPlayingVibrate |
14 | { |
15 | self |
16 | if (self) { |
17 | soundID |
18 | } |
19 | return self; |
20 | } |
21 |
22 | -(id)initForPlayingSystemSoundEffectWith:(NSString |
23 | { |
24 | self |
25 | if (self) { |
26 | NSString "com.apple.UIKit" ] |
27 | if (path) { |
28 | SystemSoundID theSoundID; |
29 | OSStatus |
30 | if (error |
31 | soundID |
32 | } else { |
33 | NSLog(@ "Failed ); |
34 | } |
35 | } |
36 |
37 | } |
38 | return self; |
39 | } |
40 |
41 | -(id)initForPlayingSoundEffectWith:(NSString *)filename |
42 | { |
43 | self |
44 | if (self) { |
45 | NSURL |
46 | if (fileURL |
47 | { |
48 | SystemSoundID theSoundID; |
49 | OSStatus |
50 | if (error |
51 | soundID |
52 | } else { |
53 | NSLog(@ "Failed ); |
54 | } |
55 | } |
56 | } |
57 | return self; |
58 | } |
59 |
60 | -( void )play |
61 | { |
62 | AudioServicesPlaySystemSound(soundID); |
63 | } |
64 |
65 | -( void )dealloc |
66 | { |
67 | AudioServicesDisposeSystemSoundID(soundID); |
68 | } |
69 | @end |
1.加入AudioToolbox.framework到工程中
2.调用WQPlaySound工具类
2.1震动
1 | WQPlaySound |
2 | [sound play]; |
2.2系统音效,以Tock为例
1 | WQPlaySound "Tock" ofType:@ "aiff" ]; |
2 | [sound play]; |
2.3自定义音效,将tap.aif音频文件加入到工程
1 | WQPlaySound "tap.aif" ]; |
2 | [sound play]; |
相关文章推荐
- iOS开发——播放系统音效、自定义音效
- iOS开发——播放系统音效、自定义音效
- iOS开发——播放系统音效、自定义音效
- iOS开发 - 播放系统音效、自定义音效
- iOS开发——播放系统音效、自定义音效
- iOS开发——播放系统音效、自定义音效
- iOS开发——播放系统音效、自定义音效
- iOS开发——播放系统音效、自定义音效
- iOS开发中让手机震动一下 播放系统音效
- iOS 之播放系统音效、自定义音效
- 实例解析iOS开发中系统音效以及自定义音效的应用
- iOS 播放系统音效,自定义音效
- ios--播放系统音效、自定义音效
- iOS开发拓展篇—音效的播放
- IOS开发之自定义系统弹出键盘上方的view(转载)
- iOS开发拓展篇—音效的播放
- iOS开发——音频篇——音效的播放
- ios开发技术——播放系统wav格式的音乐
- iOS开发中对音效和音乐播放的简单实现
- iOS开发--播放系统注册声音