Link Visual iOS Media SDK文档

更新时间:2020-03-13 10:13:56

Link Visual音视频模块使用说明:包含视频播放、语音对讲

工程配置

podfile中添加库依赖(1.0.0为.json,之后采用.podspec)
如为json文件

pod 'IMSLinkVisionMedia', :path => 'LocalPods/IMSLinkVisionMedia.podspec.json'

如为podspec

pod 'IMSLinkVisionMedia', :path => 'LocalPods/IMSLinkVisionMedia.podspec'


json拷贝以下文件至项目内LocalPods目录

IMSLinkVisionMedia.podspec.json
IMSLinkVisionMedia.framework
IMSIoTHttp2Client.framework
LibRtmp.framework
LinkVisionClientSDK.framework
FFmpeg.framework

podspec拷贝以下文件至项目内LocalPods目录

IMSLinkVisionMedia.podspec
IMSLinkVisionMedia //文件夹
//IMSLinkVisionMedia文件夹内包含以下framework
IMSLinkVisionMedia.framework
IMSIoTHttp2Client.framework
LibRtmp.framework
LinkVisionClientSDK.framework
FFmpeg.framework

执行 pod update 、则库安装完毕

视频播放器

概述

播放器按功能分为三种,提供了以下功能:
直播播放器

  • 用于RTMP直播源,具有时延低的特点.

  • 支持P2P(需使用接入LinkVisual设备端SDK的摄像头).

点播播放器

  • 用于设备录像回放的播放,可调整播放进度.

  • 支持P2P(需使用接入LinkVisual设备端SDK的摄像头).

HLS播放器

  • 用于云端录像回放的播放(iOS SDK本身不提供HLS播放器、可参照demo中使用的AVPlayerViewController HLSViewController去自定义

FFmpeg使用版本为n4.0.1
音频编码支持AAC_LC和G711a
视频编码支持H264.

功能列表:

功能 直播播放器 设备录像播放器 HLS播放器
视频播放
音频播放
暂停/恢复 X
跳至指定位置播放 X
总时长 X
当前播放进度 X
播放器状态变更通知 X
设置播放音量 X X
变速播放 X X X
循环播放 X X
画面缩放模式设置 X
播放器截图 X
边播边录 X

使用指南

创建播放器
#import <IMSLinkVisualnMedia/IMSLinkVisualMedia.h>

// 准备播放器
IMSLinkVisualPlayerViewController *vc =[[IMSLinkVisualPlayerViewController alloc] init];
self.player = vc;
[self addChildViewController:vc];
[self.view addSubview:vc.view];
vc.view.frame = self.view.bounds;
vc.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:vc.view];

设置数据源(URL)
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

// 设置数据源
[self.player setDataSource:self.url sourceType:self.sourceType];

设置数据源(直播业务)

视频播放器业务依赖于账号和用户 SDK 的初始化。

#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

// 设置直播数据源
[self.player setDataSource:self.iotId streamType:IMSLinkVisualPlayerLiveStreamTypeMain];

设置数据源(录播业务)

视频播放器业务依赖于账号和用户 SDK 的初始化。

#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

// 根据录播文件名、设置录播数据源
[self.player setDataSource:self.iotId vodFileName:record.fileName];

// 或者根据录播时间、设置录播数据源
[self.player setDataSource:self.iotId 
                          vodStartTime:self.record.beginTime 
                              vodEndTime:self.record.endTime];

开始播放
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

// 开始播放
[self.player start];

停止播放
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

// 开始播放
[self.player stop];

暂停播放(仅录播)
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

// 暂停播放
[self.player pause];

恢复播放(仅录播)
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

// 恢复播放
[self.player restore];

播放器相关通知
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

//监听播放器状态变更
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerStateChangeNotification:) name:IMSLinkVisualPlayerStateChangeNotification object:nil];

//监听播放器错误
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerErrorNotification:) name:IMSLinkVisualPlayerErrorNotification object:nil];

//监听播放器结束通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerStateEndNotification:) name:IMSLinkVisualPlayerStateEndNotification object:nil];

//播放器状态变更回调

- (void)playerStateChangeNotification:(NSNotification *)notification {
    if (notification.object != self.player) {
        return;
    }

    IMSLinkVisualPlayerState newState = [notification.userInfo[IMSLinkVisualPlayerNewStateKey] unsignedIntegerValue];

    switch (newState) {
        // 空闲
        case IMSLinkVisualPlayerStateIdle:
        // 缓冲中
        case IMSLinkVisualPlayerStateBuffering:
        // 开始播放
        case IMSLinkVisualPlayerStateStartPlay:
        // 暂停播放
        case IMSLinkVisualPlayerStatePausePlay:

    }    
}

//播放器错误通知回调

- (void)playerErrorNotification:(NSNotification *)notification {
    if (notification.object != self.player) {
        return;
    }
    // 错误内容
    NSError *error = notification.userInfo[IMSLinkVisualPlayerErrorKey];
    // 错误代码
    IMSLinkVisualPlayerError errorCode = error.code;

}

//播放器播放结束通知回调

- (void)playerStateEndNotification:(NSNotification *)notification {
    if (notification.object != self.player) {
        return;
    }
}

视频截图
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

//获取视频截图
UIImage *image = [self.player videoSnapshot];

边录边播
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

- (IBAction)recordVideoButtonClick:(UIButton *)sender {
    sender.selected = !sender.selected;
    NSString *tmpPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"tmp.mp4"];

    if (sender.selected) {
        [self.player startRecordVideoWithfilePath:tmpPath];
    } else {
        [self.player stopRecordVideo];
    }
}

播放器状态

/// 播放器状态
typedef NS_ENUM(NSUInteger,IMSLinkVisualPlayerState){
    /// 空闲
    IMSLinkVisualPlayerStateIdle,
    /// 缓冲中
    IMSLinkVisualPlayerStateBuffering,
    /// 开始播放
    IMSLinkVisualPlayerStateStartPlay,
    /// 暂停播放
    IMSLinkVisualPlayerStatePausePlay
};

错误列表

/// 错误类型
typedef NS_ENUM(NSUInteger,IMSLinkVisualPlayerError){
    /// 数据源错误或未设置
    IMSLinkVisualPlayerDataSourceError,
    /// 播放错误
    IMSLinkVisualPlayerPlayError
};

语音对讲

概述

提供App和IPC设备之间端到端的双向实时音频传输能力,需要设备接入平台,依赖于账号和用户 SDK 的初始化。

语音对讲提供如下功能:

  • 传入iotId和音频参数,自动连接语音对讲服务器,设备连接后,可以向语音对讲服务器发送音频数据、以及接收服务器返回的音频参数、数据

  • 音频管理器

    • 支持PCM数据的录音
    • 支持PCM数据的播放

语音对讲支持传输的音频格式包括PCM / AAC_LC / G711A / G711U
**

使用指南

创建语音对讲实例
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

//设置音频参数(代表了客户端传输的音频的参数)
IMSLinkVisualAudioParams *audioParams = [[IMSLinkVisualAudioParams alloc] init];
audioParams.sampleRate = 16000;
audioParams.channel = 1;
audioParams.bitsPerSample = 16;
audioParams.format = IMSLinkVisualAudioFormatPCM;

//创建语音对讲实例
self.intercom = [[IMSLinkVisualIntercom alloc] initWithIotId:self.iotId audioParams:audioParams delegate:self];

开始语音对讲
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

[self.intercom start];

传输音频数据
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

[self.intercom sendAudioData:audioData];

停止语音对讲
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

[self.intercom stop];

监听语音对讲状态
#import <IMSLinkVisualMedia/IMSLinkVisualnMedia.h>

#pragma mark 语音对讲连接服务器

- (void)linkVisualIntercomDidConnect:(IMSLinkVisualIntercom *)intercom {
    //语音对讲连接服务器成功
}

#pragma mark 语音对讲停止

- (void)linkVisualIntercomDidStop:(IMSLinkVisualIntercom *)intercom
                            error:(NSError *)error {
    //语音对讲结束
    [self showError:error];
}

#pragma mark 语音对讲出错

- (void)linkVisualnIntercom:(IMSLinkVisualIntercom *)intercom
             errorOccurred:(NSError *)error {
    //语音对讲出错
    [self showError:error];
}

#pragma mark 接收到设备端音频参数

- (void)linkVisualIntercom:(IMSLinkVisualIntercom *)intercom
     didReceiveAudioParams:(IMSLinkVisualAudioParams *)params {
    // 此时可以开始发送录音数据
}

#pragma mark 接收到设备端音频数据

- (void)linkVisualIntercom:(IMSLinkVisualIntercom *)intercom
            didReceiveData:(NSData *)data
{
    //接收到设备的音频数据,开始播放
}

初始化音频管理器(以录音功能为例)
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

// 初始化音频管理器
NSError *error = nil;
BOOL success = [[IMSLinkVisualAudioManager audioManager] activateAudioManagerMode:IMSLinkVisualAudioManagerModeRecord error:&error];
if (!success || error) {
    NSLog(@"音频管理器初始化失败");
    return;
}

// 创建音频参数类
IMSLinkVisualAudioParams *audioParams = [[IMSLinkVisualAudioParams alloc] init];
audioParams.sampleRate = 16000;
audioParams.channel = 1;
audioParams.bitsPerSample = 16;
audioParams.format = IMSLinkVisualAudioFormatPCM;

// 设置录音参数
[IMSLinkVisualAudioManager audioManager].recordDelegate = self;

success = [[IMSLinkVisualAudioManager audioManager] setRecorderAudioParams:audioParams error:&error];
if (!success || error) {
    NSLog([NSString stringWithFormat:@"录音机初始化失败,error = %@",error]);
}

获取录音数据
#import <IMSLinkVisualMedia/IMSLinkVisualMedia.h>

#pragma mark  IMSLinkVisualAudioManagerRecorderDelegate

// 录音完成回调

- (void)linkVisualAudioManager:(IMSLinkVisualAudioManager *)manager
          didReceiveRecordData:(NSData *)data {
    NSLog(@"获得麦克风录音数据");
    if (data) {
        // 通过语音对讲实例、发送录音数据给服务端
        [self.intercom sendAudioData:audioData];
    }
}

错误列表

/// 错误Code码
typedef NS_ENUM(NSUInteger, IMSLinkVisualIntercomError){
    /// 连接语音对讲服务器错误
    IMSLinkVisualIntercomConnectError,
    /// 接收数据错误
    IMSLinkVisualLinkVisualIntercomReceiveDataError
};

ChangeLog

1.0.0:

  • 初始版本

1.0.1:

  • 解决了适配新的设备端SDK P2P画面花屏的问题

版权信息

librtmp

Copyright (C) 2005-2008 Team XBMC
       http://www.xbmc.org
       Copyright (C) 2008-2009 Andrej Stepanchuk
       Copyright (C) 2009-2010 Howard Chu

 librtmp is free software; you can redistribute it and/or modify
 it under the terms of the GNU Lesser General Public License as
 published by the Free Software Foundation; either version 2.1,
 or (at your option) any later version.

 librtmp is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.

 You should have received a copy of the GNU Lesser General Public License
 along with librtmp see the file COPYING.  If not, write to
 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 Boston, MA  02110-1301, USA.
 http://www.gnu.org/copyleft/lgpl.html

FFmpeg

FFmpeg is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

FFmpeg is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with FFmpeg; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

results matching ""

    No results matching ""