# IOS SDK

# 组件介绍

下载 SDK (opens new window),在“SDK_Document.zip”查看详细介绍。

# 集成 SDK

目前只支持手动安装。您可以依据以下步骤将 SDK 集成到您的目标项目中:
步骤 1:将下载的 framework 添加或者插入到工程中:
WX20201216-163906@2x.png
步骤 2:Embedded Binaries 添加 DMH.framework
WX20201216-163922@2x.png
步骤 3:添加 Other Linker Flags : -ObjC
WX20201216-163933@2x.png
步骤 4:导入以下系统库,完成安装:

MediaPlayer.framework
AudioToolbox.framework
CoreMedia.framework
AVFoundation.framework
SystemConfiguration.framework
libstdc++.6.tdb
libz.tdb
1
2
3
4
5
6
7

# 初始化和密钥设置

导入头文件

#import <DMH/DMH.h>
1

在 AppDelegate.m didFinishLaunchingWithOptions 方法中添加初始化代码:
使用从客服获取到的 AppKey、AppSecret 来初始化授权管理
success 为 YES 表示鉴权成功,如果不成功不能正常使用数据接口

[[TDMAuthManager sharedInstance] configureWithAppKey:@"" appSecret:@"" complete:^(BOOL succes) {

}];
1
2
3

为了方便开发,可以打开或者关闭
配置用户数据调用数据调用

@interface TDMApiClient (SDKConfigure)

/*!切换API 环境*/
- (void)configureApiEnv:(TDMAPIEnvType)apiEnvType;
/*!
 配置统计信息
 @param uid 唯一标识符
 @param telephone 电话号码
 @param vipType 是否为vip   0是普通给用户 1是vip用户
 @param vipExpireTime vip到期时间,仅在vipType =1 时生效 格式为1970-01-01 23:59:59
 @param sex 性别  1男 2女
 @param birthday 生日(1970-01-01)
 @param ext1 扩展字段 1
 @param ext2 扩展字段 2
 @param ext3 扩展字段 3
 */
- (void)configureInfoWithUId:(NSString * _Nonnull)uid
                   telephone:(NSString * _Nonnull)telephone
                     vipType:(NSInteger)vipType
               vipExpireTime:(NSString * _Nonnull)vipExpireTime
                         sex:(NSString * _Nonnull)sex
                    birthday:(NSString * _Nonnull)birthday
                        ext1:(NSString * _Nonnull)ext1
                        ext2:(NSString * _Nonnull)ext2
                        ext3:(NSString * _Nonnull)ext3  TDM_API_CALLBACK_BLOCK(TDMBaseModel);;


@end

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
/*!
 *  日志管理
 */
@interface TDMLogManager : NSObject
TDM_SINGLETON_FOR_CLASS(TDMLogManager);

/*!
 启动日志打印
 */
- (void)enabled;
/*!
 *停止打印SDK日志
 */
- (void)disabled;

/*!
 *  打印日志
 *
 *  @param msg 信息
 */
- (void)log:(NSString *_Nonnull)msg,...;

/*!用于调试,外部调用无效*/
- (void)debug:(NSString *_Nonnull)msg,...;
@end
NS_ASSUME_NONNULL_END
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

# 音乐播放

# TDMPlayer 使用

初始化播放器

id<TDMPlayerItemProtocol> playSource = nil;
TDMPlayer *player = [[TDMPlayer alloc] initWithItem:playSource];
1
2

设置播放器代理

player.delegate = self;
1

播放准备

[player prepareToPlay];
1

等待播放器回调成功后 可以调用播放器 play 功能进行播放

- (void)tdm_audioPlayerDidPrepared:(TDMPlayer *)player successfully:(BOOL)flag {
 	if (flag) {
    // 准备完毕
  }
}
1
2
3
4
5

# TDMMusicPlayer 使用

初始化播放器

TDMMusicPlayer *player = [[TDMMusicPlayer alloc] init];
// 可通过 player.listManager 进行列表管理
// 最后通过 [player play]; 进行播放
1
2
3

播放列表管理

@protocol TDMPlayerItemProtocol;


/*!
 播放列表管理
 */
@interface TDMMusicListManager : NSObject
@property (atomic, assign) NSUInteger currentIndex;

#pragma mark - 播放数据操作
/*!
 添加播放音频到播放列表最后

 @param items 播放音频集合
 */
- (void)addPlayitems:(NSArray<id<TDMPlayerItemProtocol>> * _Nonnull)items;

/*!
 添加一个item 插入列表最后

 @param item item
 */
- (void)addPlayItem:(id<TDMPlayerItemProtocol> _Nonnull)item;
/*!
 添加一个播放音频 插入到指定位置

 @param item 播放音频
 @param index 插入位置
 */
- (void)addPlayItem:(id<TDMPlayerItemProtocol> _Nonnull)item atIndex:(NSUInteger)index;

/*!
 从播放列表删除一个item

 @param item 要删除的item
 @return 如果当前播放列表中有要删除的item 则删除并返回 YES 没有则返回 NO
 */
- (BOOL)deleteWithItem:(id<TDMPlayerItemProtocol> _Nonnull)item;

/*!
 从播放列表删除一个item 根据指定索引删除

 @param index 要删除的索引
 @return 如果当前播放列表中有要删除的索引 则删除并返回 YES 没有则返回 NO
 */
- (BOOL)deleteWithIndex:(NSUInteger)index;

/*!
 停止播放 并删除清空播放列表
 */
- (void)removeAllItems;

#pragma mark - 播放操作
/*!
 获取当前播放item

 @return item
 */
- (id<TDMPlayerItemProtocol> _Nullable)currentItem;

/*!
    重置播放位置为 0
 */
- (void)reset;
/*!
 播放下一曲
 */
- (void)next;

/*!
 播放上一曲
 */
- (void)prev;
#pragma mark - 其他功能
/*!
    播放数据
 */
- (NSArray<TDMPlayerItemProtocol> *)playItems;
/*!
    播放列表数量
 */
- (NSUInteger)listCount;

@end
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

TDMPlayStrategy 用于设置播放列表循环模式

/*!
 播放模式

 - TDMPlayerModeSingle: 播放模式
 */
typedef NS_ENUM(NSUInteger, TDMPlayMode) {
    TDMPlayModeListCycle,  // 列表循环  从列表第一首 到最后一首
    TDMPlayModeRandom, // 随机播放
    TDMPlayModeSingle, // 单曲循环
};


@interface TDMPlayStrategy : NSObject
@property (nonatomic, assign) TDMPlayMode mode;
@end

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# TDMPlayerItemProtocol 使用

满足此协议的对象可以作为播放数据源
使用 SDK 提供的歌曲唯一码与码率播放

/*!
 * 播放歌曲数据提供者
 * 优先 根据 歌曲id + 码率 进行选链
 * 如果 歌曲id + 码率 都没有 则选择 本地文件地址
 */
@protocol TDMPlayerItemProtocol <TDMPlaySourceProtocol>

@required
/*! 歌曲唯一 id */
- (NSString * __nonnull)tdm_songid;

@optional
/*! 将要播放的码率 如果没有设置 SDK 将会默认选择 所支持的最高码率 */
- (TDMSongQuality)tdm_songBitRate;

/*! 本地文件 URL */
- (NSURL * __nonnull)tdm_localSource;
@end

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

使用本地或者其它链接作为播放源播放

Last Updated: 12/25/2020, 2:41:19 PM