博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
AVAudioPlayer简易封装
阅读量:4699 次
发布时间:2019-06-09

本文共 2024 字,大约阅读时间需要 6 分钟。

AVAudioPlayer简易封装

 

[说明]

AVAudioPlayer简易封装,仅仅支持播放,暂停,停止,暂停时候带有渐隐效果,自己用,没有参考价值.

 

[源码]

 

一个定时器的封装类源码(该定时器可以指定运行的次数)

////  SpecialTimer.h//  Music////  Created by XianMingYou on 15/4/13.//  Copyright (c) 2015年 XianMingYou. All rights reserved.//#import 
@class SpecialTimer;@protocol SpecialTimerDelegate
@optional- (void)specialTimer:(SpecialTimer *)specialTimer CurrentCount:(NSInteger)count;@end@interface SpecialTimer : NSObject/** * 定时器代理 */@property (nonatomic, weak) id
delegate;/** * 重复执行的次数 */@property (nonatomic) NSInteger repeatTimes;/** * 定时器执行的总时间 */@property (nonatomic) NSTimeInterval totalDuration;/** * 激活定时器 */- (void)fire;/** * 让定时器无效 */- (void)invalid;@end
////  SpecialTimer.m//  Music////  Created by XianMingYou on 15/4/13.//  Copyright (c) 2015年 XianMingYou. All rights reserved.//#import "SpecialTimer.h"@interface SpecialTimer ()@property (nonatomic)         NSInteger   count;@property (nonatomic, strong) NSTimer    *timer;@end@implementation SpecialTimer- (void)fire {    // 参数没有配置就返回    if (self.repeatTimes <= 0 || self.totalDuration <= 0) {        return;    }        // 计数时间间隔    NSTimeInterval timeInterval = self.totalDuration / self.repeatTimes;        // 开启定时器    self.timer = [NSTimer scheduledTimerWithTimeInterval:timeInterval                                                  target:self                                                selector:@selector(timerEvent)                                                userInfo:nil                                                 repeats:YES];}- (void)timerEvent {    // 运行代理    if (_delegate || [_delegate respondsToSelector:@selector(specialTimer:CurrentCount:)]) {        [_delegate specialTimer:self CurrentCount:_count];    }        _count++;    if (_count >= _repeatTimes) {        _count = 0;        [self.timer invalidate];    }}- (void)invalid {    [self.timer invalidate];}@end

 

转载于:https://www.cnblogs.com/YouXianMing/p/4425453.html

你可能感兴趣的文章
LinkedList 源码小解
查看>>
js 可拖动div 调整大小
查看>>
STM32之DMA
查看>>
Spring Boot + Jersey发生FileNotFoundException (No such file or directory)
查看>>
小数(decimal,double) 截取两位或多位,不四舍五入
查看>>
面向对象
查看>>
hdu 3549 最大流(EK实现)
查看>>
@RenderBody、@RenderSection、@RenderPage、Html.RenderPartial、Html.RenderAction的作用和区别...
查看>>
微信公众平台消息接口开发(6)电话号码链接与网址链接
查看>>
URL和URI
查看>>
JAVA虚拟机内存分配原则 (转
查看>>
jar包上传到jcenter
查看>>
《黑白团团》第九次团队作业:Beta冲刺与验收准备
查看>>
团队站立会议04
查看>>
PHP计划任务:如何使用Linux的Crontab执行PHP脚本(转载)
查看>>
Working with Data Sources 2
查看>>
设计模式12——中介者模式
查看>>
小马过河
查看>>
npm和gulp学习
查看>>
一次清空所有数据方法
查看>>