本帖最后由 yxWin 于 2020-2-7 08:40 编辑
概述产品简介 阿里云推流SDK(ApsaraVideo for Live Streaming SDK)是基于阿里云强大内容分发网络和音视频实时通讯技术支持下的直播客户端推流开发工具,为用户提供简单易用的开放接口、网络自适应的流畅体验、多节点的低延迟优化、功能强大的实时美颜等音视频直播技术服务。SDK免费提供给所有开发者,让用户告别复杂的架构设计,降低维护成本,专注于自身业务逻辑实现和用户体验的提升。 使用流程 流程 : 用户APP向APPServer发起请求,获取推流URL -> AppServer根据规则拼接推流URL返回给APP -> APP赋值推流URL到推流SDK,使用推流SDK发起推流 -> 推流SDK将直播流推送到CDN 系统要求 - ios:
- SDK支持iPhone5s及以上版本,iOS8.0及以上版本
- 硬件CPU支持ARMv7、ARMv7s、ARM64
- Android:
- SDK支持Android 4.3及以上版本
- 硬件CPU支持ARM64、ARMV7
不能同时添加的模块:aliyunLive 等同样是封装阿里云SDK的模块。 注意 a、使用该模块时需要使用升级后的编译环境,请在云编译的时候勾选“使用升级环境编译”,并且在控制台 “高级设置” 中将固件版本设置为 4.3.1或以上 b、录屏时必须需关闭预览接口 ,如需预览请调用startCameraL()
主要代码
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
- <title>title</title>
- <link rel="stylesheet" type="text/css" href="../css/api.css" />
- <style>
- body {}
- footer {
- position: absolute;
- bottom: 0;
- height: 200px;
- width: 100%;
- }
- button {
- margin: 5px;
- padding: 5px;
- background-color: green;
- color: #fff;
- border-radius: 5px;
- }
- </style>
- </head>
- <body>
- <footer>
- <button type="button" name="button" onclick="initPusherL()">initPusherL</button>
- <button type="button" name="button" onclick="startPreviewL()">startPreviewL</button>
- <button type="button" name="button" onclick="startPushL()">startPushL</button>
- <button type="button" name="button" onclick="stopPushL()">stopPushL</button>
- <button type="button" name="button" onclick="pauseL()">pauseL</button>
- <button type="button" name="button" onclick="resumeL()">resumeL</button>
- <button type="button" name="button" onclick="restartPushL()">restartPushL</button>
- <button type="button" name="button" onclick="reconnectPushL()">reconnectPushL</button>
- <button type="button" name="button" onclick="destroyL()">destroyL</button>
- <button type="button" name="button" onclick="setMuteL()">setMuteL</button>
- <button type="button" name="button" onclick="switchCameraL()">switchCameraL</button>
- <button type="button" name="button" onclick="setFlashL()">setFlashL</button>
- <button type="button" name="button" onclick="setPreviewMirrorL()">setPreviewMirrorL</button>
- <button type="button" name="button" onclick="getFsPath()">getFsPath</button>
- <button type="button" name="button" onclick="startScreenCaptureL()">startScreenCaptureL</button>
- <button type="button" name="button" onclick="stopScreenCaptureL()">stopScreenCaptureL</button>
- <button type="button" name="button" onclick="startCameraL()">startCameraL</button>
- </footer>
- </body>
- <script type="text/javascript" src="../script/api.js"></script>
- <script type="text/javascript">
- var alivcLivePusher = null;
- var pushRUL = 'rtmp://***************************************26213-0-0-863767b7c94eda85bd7a4d1727566b38';
- var fsPath = '';
- apiready = function() {
- alivcLivePusher = api.require('alivcLivePusher');
- };
- //初始化推流
- function initPusherL() {
- alivcLivePusher.initPusher({
- resolution: 540,
- initialVideoBitrate: 800,
- targetVideoBitrate: 800,
- minVideoBitrate: 400,
- qualityMode: 'ResolutionFirst',
- beautyMode: 'normal',
- previewOrientation: 'PORTRAIT',
- externMainStream: true,
- fps: 20,
- videoOnly: true,
- cameraType: 'front' //back
- }, function(ret) {
- alert(JSON.stringify(ret) + '----->初始化成功');
- })
- }
- //预览
- function startPreviewL() {
- alivcLivePusher.startPreview({
- rect: {
- x: 0, //(可选项)数字类型;模块左上角的 x 坐标(相对于所属的 Window 或 Frame);默认值:0
- y: 0, //(可选项)数字类型;模块左上角的 y 坐标(相对于所属的 Window 或 Frame);默认值:0
- w: (api.frameHeight - 200) * (2/3), //(可选项)数字类型;模块宽度(相对于所属的 Window 或 Frame;默认300
- h: api.frameHeight - 200//(可选项)数字类型;模块高度(相对于所属的 Window 或 Frame;默认300
- },
- fixedOn: api.frameName,
- fixed: false
- }, function(ret) {
- alert(JSON.stringify(ret));
- })
- }
- //开始推流
- function startPushL() {
- alivcLivePusher.startPush({
- url:pushRUL
- },function(ret){
- alert(JSON.stringify(ret));
- })
- }
- //停止推流
- function stopPushL() {
- alivcLivePusher.stopPush();
- }
- //暂停推流
- function pauseL() {
- alivcLivePusher.pause();
- }
- //恢复推流
- function resumeL() {
- alivcLivePusher.resume();
- }
- //重新开始推流
- function restartPushL() {
- alivcLivePusher.restartPush();
- }
- //推流重连
- function reconnectPushL() {
- alivcLivePusher.reconnectPush();
- }
- //销毁推流
- function destroyL() {
- alivcLivePusher.destroy();
- }
- //设置静音
- function setMuteL() {
- alivcLivePusher.setMute({
- isMute:true
- });
- }
- //切换摄像头
- function switchCameraL() {
- alivcLivePusher.switchCamera();
- }
- //设置闪光灯
- function setFlashL() {
- alivcLivePusher.setFlash({
- isFlash:true
- });
- }
- //镜像预览
- function setPreviewMirrorL() {
- alivcLivePusher.setPreviewMirror({
- isMirror:true
- });
- }
- //打开美颜
- function setBeautyOnL() {
- alivcLivePusher.setBeautyOn({
- isBeautyOn:true
- });
- }
- //录屏
- function startScreenCaptureL() {
- alivcLivePusher.startScreenCapture({
- url:pushRUL,
- networkPoorImage:fsPath,
- pausePushImage:fsPath
- },function(ret){
- alert(JSON.stringify(ret));
- startCameraL();
- });
- }
- function stopScreenCaptureL() {
- alivcLivePusher.stopScreenCapture(function(ret){
- alert(JSON.stringify(ret));
- });
- }
- function startCameraL() {
- alivcLivePusher.startCamera({
- rect:{
- x:0,
- y:0,
- w:200,
- h:200
- }
- },function(ret){
- alert(JSON.stringify(ret));
- });
- }
- function getFsPath() {
- api.getPicture({
- sourceType: 'library',
- encodingType: 'jpg',
- mediaValue: 'pic',
- destinationType: 'url',
- allowEdit: true,
- quality: 50,
- targetWidth: 100,
- targetHeight: 100,
- saveToPhotoAlbum: false
- }, function(ret, err){
- if(ret){
- fsPath = ret.data
- console.log(fsPath);
- }else{
- alert(JSON.stringify(err));
- }
- });
- }
- </script>
- </html>
复制代码
如有问题欢迎指出 |