ios开发——实用技术篇Swift篇&播放MP3
播放MP3
// MARK: - 播放MP3 /*----- mp3 ------*/ //定时器- func updateTime() { //获取音频播放器播放的进度,单位秒 var cuTime:Float = Float(audioPlayer.currentTime) //更新进度条 jinDuSlider.value = cuTime //获取总时间 var duTime:Float = Float(audioPlayer.duration) //播放时间秒数,换算成:时、分、秒 var hour1:Int = Int(cuTime/(*)) var minute1:Int = Int(cuTime/) var second1:Int = Int(cuTime%) //总时间秒数,换算成:时、分、秒 var hour2:Int = Int(duTime/(*)) var minute2:Int = Int(duTime/) var second2:Int = Int(duTime%) //label显示 // timeLabel.text = NSString(format: "%.2d:%.2d:%.2d / %.2d:%.2d:%.2d",hour1,minute1,second1,hour2,minute2,second2) //2015年5月2后修改 timeLabel.text = NSString(format: "%.2d:%.2d:%.2d / %.2d:%.2d:%.2d",hour1,minute1,second1,hour2,minute2,second2) as String } //播放按钮事件 @IBAction func audioPlayButton() { if audioPlayer.playing { return;//如果已在播放,跳出 } //开始播放音频文件 audioPlayer.play() //设置进图条最小是=0 jinDuSlider.minimumValue = 0.0; //设置进度条最大值等于声音的描述 jinDuSlider.maximumValue = Float(audioPlayer.duration) //启动定时器 定时更新进度条和时间label 在updateTime方法中实现 _timer = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: "updateTime", userInfo: nil, repeats: true) } //暂停 @IBAction func audioPauseButton(sender:UIButton) { var title = sender.titleForState(UIControlState.Normal) if title == "Pause" && audioPlayer.playing { audioPlayer.pause() sender.setTitle("Continue", forState: UIControlState.Normal) } else if title == "Continue" { sender.setTitle("Pause", forState: UIControlState.Normal) audioPlayer.play() } } //停止 @IBAction func audioStopButton(sender:UIButton) { if(audioPlayer.playing) { audioPlayer.stop() audioPlayer.currentTime=; timeLabel.text = ""; } } //调 进度 @IBAction func jinDuChange(sender:UISlider) { //获取jinDuSlider的值来设置音频播放器进度 audioPlayer.currentTime = NSTimeInterval(jinDuSlider.value) //播放器播放 audioPlayer.play() } //控制声音 @IBAction func audioSoundChange(sender:UISlider) { //获取UISlider对象的值,并设置audioPlayer.volume audioPlayer.volume = sender.value aLabel.text = "\(sender.value)" } //播放代理AVAudioPlayerDelegate func audioPlayerDidFinishPlaying(player: AVAudioPlayer!, successfully flag: Bool) { //成功播放完毕结束 } func audioPlayerDecodeErrorDidOccur(player: AVAudioPlayer!, error: NSError!) { //音频播放器的解码错误 } //@availability(iOS, introduced=2.2, deprecated=8.0) func audioPlayerBeginInterruption(player: AVAudioPlayer!) { //音频播放器开始中断 } //@availability(iOS, introduced=6.0, deprecated=8.0) func audioPlayerEndInterruption(player: AVAudioPlayer!, withOptions flags: Int) { //音频播放结束中断 } /*-----mp3 end------*/
ios开发——实用技术篇Swift篇&播放MP3的更多相关文章
- ios开发——实用技术篇Swift篇&视频
视频 // MARK: - 播放视频 /*----- 播放视频 ------*/ func moviePlayerPreloadFinish(notification:NSNotification) ...
- ios开发——实用技术篇Swift篇&录音
录音 // MARK: - 录音 /*----- 录音 ------*/ var recorder:AVAudioRecorder? //录音器 var player:AVAudioPlayer? / ...
- ios开发——实用技术篇Swift篇&系统声音
系统声音 // MARK: - 系统声音 /*----- 系统声音 ------*/ @IBAction func systemSound() { //建立的SystemSoundID对象 var s ...
- ios开发——实用技术篇Swift篇&地址薄、短信、邮件
//返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControllerAnimated(tru ...
- ios开发——实用技术篇Swift篇&拍照
拍照 // MARK: - 拍照 func fromPhotograph() { if UIImagePickerController.isSourceTypeAvailable(.Camera) { ...
- ios开发——实用技术篇Swift篇&照片选择
照片选择 // MARK: - 选择照片 /*----- 选择照片 ------*/ @IBAction func addImageButtonClick() { let actionSheet = ...
- ios开发——实用技术篇Swift篇&加速计和陀螺仪
加速计和陀螺仪 //返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControllerAnim ...
- ios开发——实用技术篇Swift篇&多点触摸与手势识别
多点触摸与手势识别 //点击事件 var atap = UITapGestureRecognizer(target: self, action: "tapDo:") self.vi ...
- ios开发——实用技术篇OC篇&iOS的主要框架
iOS的主要框架 阅读目录 Foundation框架为所有的应用程序提供基本系统服务 UIKit框架提供创建基于触摸用户界面的类 Core Data框架管着理应用程序数据模型 Core ...
随机推荐
- 【LeetCode】66 & 67- Plus One & Add Binary
66 - Plus One Given a non-negative number represented as an array of digits, plus one to the number. ...
- Mac OS10.9 下python开发环境(eclipse)以及自然语言包NLTK的安装与注意
折腾了大半天,终于把mbp上python自然语言开发环境搭建好了. 第一步,安装JDK1.7 for mac MacOS10.9是自带python2.7.5的,够用,具体的可以打开终端输入python ...
- linux常用的一些命令(不断增加中)
linux 下重启 apache: httpd -k restart 下面这些大多命令都可以在<鸟哥私房菜>的服务器中的“常用网络指令”和基础中的“程序与资源管理”中找到ps -aux 这 ...
- 在linnux下,配置自动备份oacle
以oracle身份登录到linux,在oracle home目录下创建目录 shell $ mkdir shell 创建自动备份脚本 $ cd shell $ touch expdp.sh $ chm ...
- Labview中局部变量和全局变量
局部变量的作用域是整个VI,它用于在单个VI中传输数据: 全局变量的作用域是整台计算机,它主要用于多个VI之间共享数据
- 摄影初学者挑选相机的常见问题 FAQ
数码相机一次次降价,越来越多的人加入摄影的行列,照相器材还是一个比较专业的领域,并非简单的参数比一下高低就可以知道好坏,很多朋友往往了解了好久还没弄清孰优孰劣,在购机前踌躇半天拿不定主意,我收集了被问 ...
- Session的实现与存储
[集群中session安全和同步] 使用数据库来保存session,就算服务器宕机了也没事,session照样在. 每次请求都进行数据库读写开销不小(使用内存数据库可以提高性能,宕机就会丢失数据. ...
- IIS7/8 HTTP Error 500.19 错误 0x80070021
IIS7.0/8.0的错误HTTP Error 500.19 - Internal Server Error ,错误代码为0x80070021,大概原因为IIS7.0的安全设定相比前版本有很大的变更. ...
- Ruby学习资源汇总
from:http://segmentfault.com/a/1190000000362058 Ruby 语言 Try Ruby: 无需在你的系统中安装.Ruby,只要通过浏览器便可立即体验 Ruby ...
- 关于以DataTable形式批量写入数据的案例
void IDataAccess.CommandDataTable(DataTable dt, string ProcedureName, System.Data.Common.DbParameter ...