CNLiveBgmPlayer.h
3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// CNLiveBgmPlayer.h
// CNLivePlayer_Example
//
// Created by CNLive-zxw on 2019/8/21.
// Copyright © 2019 153993236@qq.com. All rights reserved.
//
/**
* 背景音乐播放器
*/
#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import "CNLivePlayerDefines.h"
NS_ASSUME_NONNULL_BEGIN
@interface CNLiveBgmPlayer : NSObject
// Posted when audio state changes
FOUNDATION_EXPORT NSString *const CNLiveBgmAudioStateDidChangeNotification;
/**
@abstract 开始播放背景音乐
@param path 本地音乐的路径
@param loop 是否循环播放此音乐
@return 是否能够开始播放
*/
- (BOOL)startPlayBgm:(NSString *)path isLoop:(BOOL)loop;
/**
@abstract 停止播放背景音乐
*/
- (void)stopPlayBgm;
/**
@abstract 暂停播放背景音乐
*/
- (void)pauseBgm;
/**
@abstract 恢复播放背景音乐
*/
- (void)resumeBgm;
/**
@abstract seek到指定时间 (拖动进度条)
@param time 时间, 请参考 bgmDuration (单位,秒)
@return 是否seek 成功
*/
- (BOOL)seekToTime:(float)time;
/**
@abstract seek到指定进度 (拖动进度条)
@param prog 进度, 请参考 bgmProgress
@return 是否seek 成功
*/
- (BOOL)seekToProgress:(float)prog;
/**
@abstract 背景音乐的音量
@discussion 调整范围 0.0~1.0
@discussion 仅仅调整播放的音量, 不影响回调的音频数据
*/
@property (nonatomic, assign) double bgmVolume;
/**
@abstract 播放声音的音调
@discussion 调整范围 [-24.0 ~ 24.0], 默认为0.01, 单位为半音
@discussion 0.01 为1度, 1.0为一个半音, 12个半音为1个八度
*/
@property (nonatomic, assign) double bgmPitch;
/**
@abstract 背景音乐播放静音
@discussion 仅仅静音播放, 不影响回调的音频数据
*/
@property (nonatomic, assign) BOOL bMutBgmPlay;
#pragma mark - callbacks
/**
@abstract 音频数据输出回调
@discussion sampleBuffer 从音乐文件中解码得到的PCM数据
*/
@property (nonatomic, copy) BOOL (^cnBgmAudioDataBlock)(uint8_t** pData, int len, const AudioStreamBasicDescription* fmt, CMTime pts);
/**
@abstract 当背景音乐播放完成时,调用此回调函数
@discussion 只有设置 loop为NO时才有效, 在开始播放前设置有效
*/
@property (nonatomic, copy) void(^cnBgmFinishBlock)(void);
#pragma mark - player state
/**
@abstract 背景音的duration信息(总时长, 单位:秒)
*/
@property (nonatomic, readonly) float bgmDuration;
/**
@abstract 背景音的已经播放长度 (单位:秒)
@discussion 从0开始,最大为bgmDuration长度
*/
@property (nonatomic, readonly) float bgmPlayTime;
/**
@abstract 音频的播放进度
@discussion 取值从0.0~1.0,大小为bgmPlayTime/bgmDuration;
*/
@property (nonatomic, readonly) float bgmProcess;
/**
@abstract 音频播放是否运行
@discussion 音频是否输出到speaker播放
*/
@property (nonatomic, readonly) BOOL isRunning;
/**
@abstract 播放错误码
@discussion 播放错误码具体内容可以参考AudioQueue的Apple文档。
*/
@property (nonatomic, readonly) OSStatus audioErrorCode;
/**
@abstract 播放状态
*/
@property (nonatomic, readonly) CNLiveBgmPlayerState bgmPlayerState;
/**
@abstract 单曲循环
*/
@property (nonatomic, assign) BOOL bLoop;
@end
NS_ASSUME_NONNULL_END