zoukankan      html  css  js  c++  java
  • AVAudioPlayer简易封装

    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

  • 相关阅读:
    链表问题(5)-----读取
    链表问题(4)----环形链
    服务器上安装anaconda
    链表问题(3)-----反转
    (1)安装vagrant和virtualbox
    链表问题(2)-----删除
    链表问题(1)----遍历和实现
    Python笔记26----正则表达式匹配
    读书笔记--SQL必知必会04--过滤数据
    Docker
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/4425453.html
Copyright © 2011-2022 走看看