LDSAppOpenSDK
示例
要运行示例项目,请克隆仓库,并首先从 Example 目录运行 pod install
命令。
要求
安装
LDSAppOpenSDK 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod 'LDSAppOpenSDK'
作者
许可证
LDSAppOpenSDK可在MIT许可证下使用。有关更多信息,请参阅LICENSE文件。
iOS SDK接口说明
特别说明1:此SDK仅包含真实机调试功能,不支持任何模拟器调试。
特别说明2:此SDK提供的功能已在文档中解释。任何未在文档中描述的功能不支持,用户可请求我们改进功能。
介绍
本文件用于说明LDS开放平台SDK iOS版本接口与接口调用顺序之间的关系。详细描述了开放平台SDK iOS版本的接口。
示例配置
关闭位码
快速示例
1.获取视频列表
+ (void) _getDevListWithCallback:(void (^_Nonnull)(NSArray<LDSDeviceInfo*>* _Nullable list,int totalCount, NSError* _Nullable error))callback;
描述:通过调用 _getDevListWithCallback
,您可以获取一个列表( LDSDeviceInfo
对象数组),其中每个项目包含相机信息。开发者可以通过UITableView显示列表。
接口位于
LDSAppOpenSDK.h
文件的第 51 行。示例代码是
CameraListViewController
。
添加设备
注意:当您需要添加设备时,可以单击界面 1 中的加号(+),进入界面 2。
步骤1
步骤2
输入 wifi名称和密码,使相机连接到互联网。
步骤3
转到设置 wifi 页面,选择相机 wifi(LDS_IPC_XXX),然后转到此页面。
步骤4
等待相机与服务器绑定
/**
add device
@param ssid name of wifi
@param psw password of wifi
@param callback callback
*/
+ (void) startAddDeviceWifi:(NSString *_Nonnull)ssid andPassword:(NSString *_Nonnull)psw
callback:(void (^_Nonnull)(BIND_DEVICE_STATE result))callback;
回调将返回绑定状态和结果
typedef enum : NSUInteger {
BIND_STATE_UNKOWN = 0,//not start bind or just start bind
BIND_STATE_SSIDERROR = 2,//ssid is not "IPC_XXX"
BIND_STATE_DICOVERDEVIC_SUCCESS = 100,//disover device success
BIND_STATE_SENDUSERINFO_SUCCESS = 110,//discover device failed
BIND_STATE_DICOVERDEVIC_TIMEOUT = 200,//send userinfo to device success
BIND_STATE_SENDUSERINFO_TIMEOUT = 120, //send userinfo to device failed
BIND_STATE_SENDWIFIINFO_SUCCESS = 111, //send wifiinfo to device failed
BIND_STATE_SENDWIFIINFO_TIMEOUT = 112, //send wifiinfo to device failed
BIND_STATE_FORMATE_RROR = 1001,//uid or devid error
BIND_STATE_SUCCESS = 1000,//bind to cloud device success
BIND_STATE_TIMEOUT = 1002,//bind to cloud device failed
BIND_STATE_BIDING = 1003,//is binding
} BIND_DEVICE_STATE;
在这种情况下,简单的设备添加就已完成。
接口代码位于
LDSAppOpenSDK
,示例代码位于第 60 行的BindturntoWifiViewController
。
3.直播预览
请参阅 CameraLiveViewController
以获取预览视频的代码。
self.xplayer = [LDSAppOpenSDK createPlayerWithDeviceSerial:_deviceId andType:LDSXplayerLiveType];
self.xplayer.delegate = self;
[self.xplayer setPlayerView:self.playerView];
[self.xplayer startRealPlay];
代码描述
1,创建一个 LDSXplayer
对象需要一个 DeviceSerial
id,相机的唯一 id,此相机Id 可以从 LDSDeviceInfo
对象中获取
2,您需要实现 LDSPlayerDelegate
方法
@protocol LDSPlayerDelegate <NSObject>
- (void)playerEventNotify:(LDSXplayer *)player didReceviedCode:(LDSErrorCode)errorCode adidPlayFailed:(NSError *)error;
- (void)playerEventNotify:(LDSXplayer *)player didReceviedCode:(LDSMessageCode )messageCode andMsg:(NSDictionary *)message;
@end
现在,预览功能基本上已经完成。
4.相机回放
关于回放功能的代码,请参阅 CloudPlayBackViewController
文件。主要核心功能包括
//Query Camera cloud storage video
+ (void)queryCloudRecord:(NSString *)deviceSerial
andStartTime:(NSString *)startTime
andEndTime:(NSString *)endTime
andPageNum:(NSInteger )pageNum
andPageSize:(NSInteger )pageSize
callback:(void (^)(NSDictionary * _Nullable, NSError * _Nullable))callback
开始回放(需要两步)
- 首先构建
LDSXplayer
对象
self.xplayer = [LDSAppOpenSDK createPlayerWithDeviceSerial:_devId andType:LDSXplayerCloudRecordType];
self.xplayer.delegate = self;
[self.xplayer setPlayerView:self.playerView];
代码描述:在 CloudPlayBackViewController
文件的第 37 行构建 EZPlayer
- 开始云存储回放
weakSelf.pullList = dic[@"data"][@"list"];//queryCloudRecord callback dic
[self.xplayer startPlayback:_pullList];
代码描述:在第 79 ~ 111 行的 CloudPlayBackViewController
中播放拉动和开始
5.SDK 初始化
#define kLDSAppOpenSDKKey @"appa070"
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[LDSAppOpenSDK initLibWithAppKey:kLDSAppOpenSDKKey];
return YES;
}
描述:SDK在程序启动时初始化,初始化时需要设置AppKey。
6.登录相关接口
//HTTPRequest
+ (void) loginWithUserName:(NSString *_Nonnull)username passwd:(NSString *_Nonnull)passwd callback:(void (^_Nonnull)(NSDictionary * _Nullable response, NSError * _Nullable error))callback;
+ (void) setHeader:(NSDictionary *_Nonnull)header;
+ (void) reqUserAuthInfoWithCallback:(void (^_Nonnull)(NSDictionary * _Nullable response, NSError * _Nullable error))callback;
//LDSAppOpenSDK line 42
+ (void) setAuthInfo:(LDSAuthInfo *_Nonnull)authInfo;
接口描述
第一步是通过使用+(void) loginWithUserName:(NSString *_Nonnull)username passwd:(NSString *_Nonnull)passwd callback:
方法获取token对象accessToken;
第二步,将获得的AccessToken字符串通过+(void) setHeader:
方法设置给SDK;
第三步,用户可以使用+(void) reqUserAuthInfoWithCallback:
方法获取用户AuthInfo
然后将authinfo保存到LDSAppOpenSDK
7.设备相关接口
1.WiFi配置
/**
add device
@param ssid name of wifi
@param psw password of wifi
@param callback callback
*/
+ (void) startAddDeviceWifi:(NSString *_Nonnull)ssid
andPassword:(NSString *_Nonnull)psw
callback:(void (^_Nonnull)(BIND_DEVICE_STATE result))callback;
接口描述
WiFi配置注意事项:全新设备,序列号查询结果必须为设备不存在。请确保在第二次及之后的WiFi配置前重置设备,然后配置WiFi。
2.回放相关接口
/**
* start cloud remote play,async api,return operation success,not play success
*
* @param deviceSerial cloud deviceSerial
*
* @param startTime cloud file startTime
*
* @param endTime cloud file endTime
*
* @param pageNum cloud file pageNum [1~N]
*
* @param pageSize onepage return Size
*
* @param callback NSDictionary dic[@"data"][@"list"] NSError *error
*/
+ (void)queryCloudRecord:(NSString *)deviceSerial
andStartTime:(NSString *)startTime
andEndTime:(NSString *)endTime
andPageNum:(NSInteger )pageNum
andPageSize:(NSInteger )pageSize
callback:(void (^)(NSDictionary * _Nullable, NSError * _Nullable))callback;
8.LDSXplayer相关接口
/**
* set LDSXplayer deviceSerial
*
* @param deviceSerial device Serial
*
* @param type LDSplay type
*/
+ (instancetype)createPlayerWithDeviceSerial:(NSString *)deviceSerial andType:(LDSXplayerType)type;
/**
* set LDSXplayer view
*
* @param view show view Frame
*
*/
- (void)setPlayerView:(UIView *)view;
/**
* release LDSXplayer
*
*/
- (void)releasePlayer;
接口描述:构建LDSXplayer
后,必须设置玩家携带的视图对象,否则将没有回放屏幕。
1.预览界面
/**
* start play,async api,
*
*/
- (void)startRealPlay;
/**
* stop play,async api,
*/
- (void)stopRealPlay;
注意:在调用startRealPlay之后,记得调用stopRealPlay,以确保方法成对出现,否则容易发生问题。
2.设置视频分辨率
/**
* change video resolution
*
* @param quality LDSVideoQuality
*/
- (void)selectResoultion:(LDSVideoQuality)quality;
3.声音切换
/**
* mute yes close sound
*
* @param mute yes/no
*/
- (void)mute:(BOOL)mute;
接口描述:声音切换仅在开始播放后才生效。
4.语音对讲(目前仅支持半双工对讲)
/**
* start talk,async api,
*
*/
- (void)startVoiceTalk;
/**
* stop talk,async api,
*
*/
- (void)stopVoiceTalk;
注意:在调用startVoiceTalk之后,记得调用stopVoiceTalk,以确保方法成对出现,否则容易出现问题;如果离开页面,releasePlayer不需要调用stopVoiceTalk。
5 capturedimages
/**
* capture live picture
*
* @return image
*/
- (UIImage *)captureImage;
图像接口直接获取UIImage对象。你可以保存或显示它。
回放播放
播放界面
/**
* start remote play
*/
- (void)startPlayback:(NSArray*)timelist;
typedef NS_ENUM(NSInteger, LDSPlaybackControl) {
LDS_PLAYBACK_CONTROL_PAUSE = 1, // pause
LDS_PLAYBACK_CONTROL_RESUME=2, // resume
};
/**
* remote playback control
*
* @param controlCode LDSPlaybackControl
*/
- (void)playControl:(LDSPlaybackControl)controlCode;
/**
* stop remote play
*/
- (void)stopPlayback;
LDSPlayer代理人接口
@protocol LDSPlayerDelegate <NSObject>
@optional
/**
* LDSPlayer play failed error callback
*
* @param player LDSPlayer object
* @param error LDSPlayer error
*/
- (void)playerEventNotify:(LDSXplayer *)player didReceviedCode:(LDSErrorCode)errorCode adidPlayFailed:(NSError *)error;
/**
* LDSPlayer play message callback
*
* @param player LDSPlayer object
* @param messageCode LDSPlayer messageCode
*/
- (void)playerEventNotify:(LDSXplayer *)player didReceviedCode:(LDSMessageCode )messageCode andMsg:(NSDictionary *)message;
@end
接口描述
playerEventNotify: 回调播放器的某些状态;
错误回调:播放器播放失败,用户可以根据错误代码判断错误的发生。
LDSXplayer枚举值
typedef NS_ENUM(NSInteger, LDSXplayerType) {
LDSXplayerLiveType = 0, //live
LDSXplayerCloudRecordType = 1, //cloud
LDSXplayerDeviceRecordType = 2 //device
};
/* live videoQuailty */
typedef NS_ENUM(NSInteger, LDSVideoQuality) {
LDSVideoQualityHigh = 0x01, //high
LDSVideoQualityLow = 0x05, //low
};
/* Player LDSPlayer state message define */
typedef NS_ENUM(NSInteger, LDSMessageCode) {
PLAYER_REALPLAY_START = 20001, //live start
PLAYER_REALPLAY_START_SUCCESS = 20002, //live start success
PLAYER_REALPLAY_STOP = 20003 , //live stop
PLAYER_REALPLAY_STOP_SUCCESS = 20004, //live stop success
PLAYER_SET_VIDEOLEVEL = 20005, //live videoQuailty change
PLAYER_SET_VIDEOLEVEL_SUCCESS = 20006, //live videoQuailty change
PLAYER_GET_VIDEOLEVEL = 20007, //live videoQuailty change
PLAYER_GET_VIDEOLEVEL_SUCCESS = 20008, //live videoQuailty change
PLAYER_STREAM_RECONNECT = 20009, //live reconnect
PLAYER_VOICE_TALK_START = 20010, //live talk start
PLAYER_VOICE_TALK_START_SUCCESS = 20011 , //live talk start
PLAYER_VOICE_TALK_STOP= 20012, //live talk stop
PLAYER_VOICE_TALK_STOP_SUCCESS = 20013,//live talk stop success
PLAYER_WIDTH_AND_HEIGHT_INFO= 20014, //player width and height
PLAYER_PLAYBACK_START = 20015, //record playback start
PLAYER_PLAYBACK_TIMESTAMP = 20016 , //record playback start
PLAYER_PLAYBACK_STOP= 20017 , //record playback stop
PLAYER_PLAYBACK_RESUME= 20018, //record stop by user
PLAYER_PLAYBACK_PAUSE= 20019, //record palyback pause
PLAYER_REALPLAY_STREAM_SPEED = 20020, //live stream speed
};
/* Player LDSErrorCode state message define */
typedef NS_ENUM(NSInteger, LDSErrorCode) {
PLAYER_CREATE_PLAYER_ERROR = 30001, //player setplayerView error
PLAYER_SET_PLAYERVIEW_ERROR = 30002 , //player setplayerView error
PLAYER_START_REALPLAY_ERROR = 30003, //player live start error
PLAYER_STOP_REALPLAY_ERROR = 30004, //player live realplay stop error
PLAYER_RELEASE_REALPLAY_ERROR = 30005, //player realplay release error
PLAYER_START_VOICE_TALK_ERROR = 30006, //player live talk start error
PLAYER_STOP_VOICE_TALK_ERROR = 30007, //player live talk stop error
PLAYER_CAPATURE_IMAGE_ERROR = 30008, //player record capature error
PLAYER_MUTE_ERROR= 30009 , //player record mute error
PLAYER_CHANGE_VIDEORESOULTION_ERROR = 30010, //live Resoultion change error
PLAYER_START_LOCALRECORD_ERROR= 30011 , //player record localRecord start error
PLAYER_STOP_LOCALRECORD_ERROR= 30012 , //player record localRecord stop error
PLAYER_PLAY_CLOUD_RECORD_ERROR = 30013, //player cloud record play error
PLAYER_PLAY_DEVICE_RECORD_ERROR = 30014, //player device record play error
PLAYER_START_PLAYBACK_ERROR= 30015 , //player record playback start error
PLAYER_STOP_PLAYBACK_ERROR = 30016, //player record playback stop error
PLAYER_PAUSE_PLAYBACK_ERROR= 30017 , //player pause error
PLAYER_RESUME_PLAYBACK_ERROR = 30018 , //player resume error
};
typedef NS_ENUM(NSInteger, LDSPlaybackControl) {
LDS_PLAYBACK_CONTROL_PAUSE = 1, // pause
LDS_PLAYBACK_CONTROL_RESUME=2, // resume
};