首页 > 其他 > 详细

AVAudioPlayer简易封装

时间:2015-04-14 22:49:23      阅读:115      评论:0      收藏:0      [点我收藏+]

AVAudioPlayer简易封装

技术分享

 

[说明]

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

 

[源码]

https://github.com/YouXianMing/AVAudioPlayer-

 

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

//
//  SpecialTimer.h
//  Music
//
//  Created by XianMingYou on 15/4/13.
//  Copyright (c) 2015年 XianMingYou. All rights reserved.
//

#import <Foundation/Foundation.h>

@class SpecialTimer;

@protocol SpecialTimerDelegate <NSObject>
@optional
- (void)specialTimer:(SpecialTimer *)specialTimer CurrentCount:(NSInteger)count;

@end

@interface SpecialTimer : NSObject

/**
 *  定时器代理
 */
@property (nonatomic, weak) id<SpecialTimerDelegate>   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

技术分享

 

AVAudioPlayer简易封装

原文:http://www.cnblogs.com/YouXianMing/p/4425453.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!