ios播放声音和振动
来源:互联网 发布:西安澳鹏网络,面试 编辑:程序博客网 时间:2024/04/29 10:28
首先需要引入头文件:
#import <AudioToolbox/AudioToolbox.h>
下面是方法
========================1.播放声音===============================
/**
* 系统铃声播放完成后的回调*/
void SystemSoundFinishedPlayingCallback(SystemSoundID sound_id, void* user_data)
{
//通过传递的SoundID,当播放完声音时,结束掉声音
}
// 播放接收到新消息时的声音
- (SystemSoundID)playNewMessageSound
{
// 要播放的音频文件地址
NSURL *bundlePath = [[NSBundle mainBundle] URLForResource:@"bundle的路径" withExtension:@"bundle"];
NSURL *audioPath = [[NSBundle bundleWithURL:bundlePath] URLForResource:@"in" withExtension:@"caf"];
// 创建系统播放声音,同时标识一个声音的ID
SystemSoundID soundID;
AudioServicesCreateSystemSoundID((__bridge CFURLRef)(audioPath), &soundID);
// 注册声音,同时监听播放完后回调。
AudioServicesAddSystemSoundCompletion(soundID,
NULL, // NULL为主循环
NULL, // 循环的模式为kCFRunLoopDefaultMode
SystemSoundFinishedPlayingCallback, // 回调函数,并播放声音
NULL // 为了data设置的,我们不需要设置,所以设置为 NULL
);
//播放声音
AudioServicesPlaySystemSound(soundID);
return soundID;
}
=========================2.播放振动==============================
// 震动
- (void)playVibration
{
// Register the sound completion callback.
AudioServicesAddSystemSoundCompletion(kSystemSoundID_Vibrate,
NULL, // uses the main run loop
NULL, // uses kCFRunLoopDefaultMode
EMSystemSoundFinishedPlayingCallback, // the name of our custom callback function
NULL // for user data, but we don't need to do that in this case, so we just pass NULL
);
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
}
- ios播放声音和振动
- iOS——播放声音和振动
- iOS 系统声音和振动
- iOS调用系统声音和振动
- ios 中添加frameworok,实现软件声音和振动
- iOS如何获取设备声音和振动功能
- ios 播放声音和震动
- IOS 播放声音和震动
- iOS 播放声音和震动
- iOS 播放声音和震动
- iOS调用系统声音与振动
- IOS 实现声音的录制和播放
- iOS 声音的录制和播放
- ios中闹钟和播放系统声音
- 消息通知声音和振动提示
- Android中的声音和振动功能
- 控制notification的声音和振动(转)
- IOS-播放声音,中断声音
- as中依赖管理
- python中的subprocess子进程
- Android手机缓存的位置
- iOS 之 AutoresizesSubviews ——自动尺寸调整行为
- linux posix 通过pthread_join获取线程pthread_exit返回的数据
- ios播放声音和振动
- 使用DOM操作样式表
- AS导入jar包和so库
- iOS9支付宝移动开发笔记--MollyMmm
- ios常用宏定义
- git使用笔记
- QML动画
- Webdriver+Testng实现测试用例失败自动截图功能
- C语言宏定义使用技巧