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

目录
相关文章
|
1天前
|
Java API
什么是Java函数式接口?
【4月更文挑战第13天】
4 0
什么是Java函数式接口?
|
7月前
|
Java 程序员
Java函数式接口详解
Java是一门强类型、面向对象的编程语言,但在Java 8引入了函数式编程的概念,这为我们提供了更多灵活的编程方式。函数式接口是函数式编程的核心概念之一,本文将详细介绍Java函数式接口的概念、用法以及一些实际应用。 什么是函数式接口?
94 0
|
7月前
|
Java
Java函数式接口
Java函数式接口
28 0
|
8月前
手动封装call
手动封装call
29 0
|
8月前
|
前端开发
手动封装call
手动封装call
34 0
|
移动开发 前端开发 小程序
基于wx.request封装类似axios的请求方法
基于wx.request封装类似axios的请求方法
255 0
|
程序员
Dio 封装之金屋藏娇
小王在成为老王之前,为人处事很谨慎。譬如说,他有了女朋友,他呢又想让别人知道自己有女朋友了,但是又不想让别人知道自己的女朋友是谁……
314 0
Dio 封装之金屋藏娇
|
Java 数据安全/隐私保护 Android开发
【Binder 机制】Native 层 Binder 机制分析 ( binder_loop | svcmgr_handler | binder.c | binder_parse )
【Binder 机制】Native 层 Binder 机制分析 ( binder_loop | svcmgr_handler | binder.c | binder_parse )
140 0
CAShapeLayer 类解析
CAShapeLayer类解析(一) —— 基本概览CAShapeLayer类解析(二) —— 基本使用
783 0