帖子
帖子
用户
博客
课程

qiniuLive模块 解决拉流端模糊问题 示例

YonBuilder移动开发 2022-4-15 13:16 493人浏览 0人回复
原作者: yxWin 收藏 邀请
摘要

qiniuLive模块推流成功后拉流端湖可能会出现画面 模糊等问题。 这说明你的配置不是最佳的。 分享一个我个人感觉比较清晰流畅的 案例 (调试了好久 在 Android 端 推流与拉流的开始 都需要在 监听里执行监听状态码 ...

qiniuLive模块推流成功后拉流端湖可能会出现画面 模糊等问题。
这说明你的配置不是最佳的。
分享一个我个人感觉比较清晰流畅的 案例 (调试了好久  

在 Android 端 推流与拉流的开始 都需要在 监听里执行  监听状态码
文档连接 https://docs.apicloud.com/Client-API/Open-SDK/qiniuLive
注意: 测试时或运行时 打开推流关闭后要销毁,自定义loader调试重启页面也要先销毁一下再测试
,否则内存溢出会闪退。
推流端 代码的实现
  1. <!DOCTYPE html>
  2. <html>

  3. <head>
  4.     <meta charset="utf-8">
  5.     <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  6.     <title>title</title>
  7.     <link rel="stylesheet" type="text/css" href="../css/api.css" />
  8.     <style>
  9.         body {}
  10.           footer{
  11.             width: 100%;
  12.             padding: 30px;
  13.             position: absolute;
  14.             bottom: 0px;
  15.             text-align: center;
  16.           }
  17.           button{
  18.             padding: 8px;
  19.             margin: 5px;
  20.             border-radius: 5px;
  21.             background-color: green;
  22.             color: #fff;
  23.           }
  24.     </style>
  25. </head>

  26. <body>
  27. <footer>
  28.   <button type="button" name="button" onclick="Profile()">预览</button>
  29.   <button type="button" name="button" onclick="changeCamera()">切换摄像头</button>
  30.   <button type="button" name="button" onclick="stopStreamQ()">关闭推流</button>
  31.   <button type="button" name="button" onclick="destroy()">销毁</button>

  32. </footer>
  33. </body>
  34. <script type="text/javascript" src="../script/api.js"></script>
  35. <script type="text/javascript">
  36.     var qiniuLive = null;
  37.     apiready = function() {
  38.         qiniuLive = api.require('qiniuLive');
  39.         setTimeout(function () {
  40.           initQi();
  41.         }, 2000);
  42.     };

  43.     function initQi() {
  44.         qiniuLive.initStreamingEnv(function(ret) {
  45.             console.log('初始化成功-----》' + JSON.stringify(ret));
  46.             addEventListen();
  47.         });
  48.     }

  49.     function Profile() {
  50.       var quikeid = '*******************************************hOF49rIM5av8MfJJ326noohMJE=';
  51.         qiniuLive.setStreamingProfile({
  52.             rect: {
  53.                 x: 0,
  54.                 y: 0,
  55.                 w: api.frameWidth,
  56.                 h: api.frameWidth * (4/3)
  57.             },
  58.             remoteWindowRect: [{
  59.                 x: api.frameWidth - 120,
  60.                 y: api.frameWidth * (4/3) - 160,
  61.                 w: 120,
  62.                 h: 160
  63.             }],
  64.             pushUrl: quikeid,
  65.             videoCapture: {
  66.                 videoFrameRate: 20,
  67.                 sessionPreset: '1280*720',
  68.                 previewMirrorFrontFacing: true,
  69.                 previewMirrorRearFacing: false,
  70.                 streamMirrorFrontFacing: false,
  71.                 streamMirrorRearFacing: false,
  72.                 videoOrientation: 'portrait',
  73.                 cameraPosition: 'front'
  74.             },
  75.             previewSetting: {
  76.                 previewSizeLevel: 'small', // 字符类型;相机预览大小等级
  77.                 // 取值范围:small, medium, large
  78.                 previewSizeRatio: 'ratio_4_3' // 字符类型;相机预览大小比例 //这个会改变本地的比例大小吗?
  79.                     // 取值范围:ratio_4_3, ratio_16_9
  80.             },
  81.             videoEncodeHeight: '1080',
  82.             videoStream: {
  83.                 videoSize: {
  84.                     width: 368,
  85.                     height: 640
  86.                 },
  87.                 videoQuality: 'medium3'
  88.             },
  89.             audioQuality:'high',
  90.             localWinPosition: {
  91.                 x: 0,
  92.                 y: 0,
  93.                 w: 480,
  94.                 h: 640
  95.             },
  96.             encodeOritation: "protrait",
  97.             face: {
  98.                 beautify: false,
  99.                 setBeautify: 0,
  100.                 setWhiten: 0,
  101.                 setRedden: 0
  102.             },
  103.             continuousFocus: false,
  104.             fixedOn: api.frameName,
  105.             fixed: true
  106.         }, function(ret) {
  107.             if (ret.status) {
  108.                 console.log('setStreamingProfile成功' + JSON.stringify(ret));

  109.             }
  110.         });

  111.     }
  112.     function addEventListen() {
  113.       qiniuLive.addEventListener({
  114.            name: 'streamStatus'
  115.       },function(ret) {
  116.            if (ret.streamStatus == 17) {
  117.              console.log('准备就绪可以推流--------->' + JSON.stringify(ret));
  118.              qiniuLive.startStream(function(ret){
  119.                   console.log('推流成功-------->' + JSON.stringify(ret));
  120.               });
  121.            }
  122.       });
  123.     }
  124.     function destroy() {
  125.       qiniuLive.destroyStream();
  126.     }
  127.     function changeCamera() {
  128.       qiniuLive.toggleCamera();
  129.     }
  130.     function stopStreamQ() {
  131.       qiniuLive.stopStream(function(ret){
  132.           console.log('推流结束------->' + JSON.stringify(ret));
  133.       });
  134.     }
  135. </script>

  136. </html>
复制代码
拉流端 代码的实现
  1. <!DOCTYPE html>
  2.   <html>
  3.   <head>
  4.       <meta charset="utf-8">
  5.       <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
  6.       <title>title</title>
  7.       <link rel="stylesheet" type="text/css" href="../css/api.css"/>
  8.       <style>
  9.           body{

  10.           }
  11.           footer{
  12.             position: absolute;
  13.             bottom: 0;
  14.             width: 100%;
  15.             height: 50px;
  16.             text-align: center;
  17.           }
  18.       </style>
  19.   </head>
  20.   <body>
  21. <footer>
  22.   <h1>拉流端</h1>
  23. </footer>
  24.   </body>
  25.   <script type="text/javascript" src="../script/api.js"></script>
  26.   <script type="text/javascript">
  27.       apiready = function(){
  28.         // api.addEventListener({
  29.         //     name:'swipedown'
  30.         // }, function(ret, err){
  31.         //    alert('向下轻扫');
  32.         // });
  33.         setTimeout(function () {
  34.           fninitPMediaPlayer();
  35.         }, 3000);
  36.       };
  37.       function fninitPMediaPlayer() {


  38.         var qiniuLive = api.require("qiniuLive");
  39.         qiniuLive.addEventListener({
  40.              name: 'status'
  41.         },function(ret) {
  42.              if (ret.status == 2 ) {
  43.                qiniuLive.start(function(ret) {
  44.                    alert(JSON.stringify(ret));
  45.                 });
  46.              }
  47.         });
  48.         qiniuLive.initPMediaPlayer({
  49.           rect: {
  50.              x: 0,
  51.              y: 0,
  52.              w: api.frameWidth,
  53.              h: api.frameWidth * (4/3)
  54.           },
  55.           dataUrl: 'http://pili***************************************615891.m3u8',
  56.           codec: 0,
  57.           prepareTimeout: 10000,
  58.           readTimeout: 10000,
  59.           isLiveStream: false,
  60.           isDelayOptimization: false,
  61.           cacheBufferDuration: 2000,
  62.           maxCacheBufferDuration: 4000,
  63.           fixedOn: api.frameName,
  64.           fixed: true
  65.           },function(ret) {

  66.           });
  67.       }
  68.   </script>
  69.   </html>
复制代码
运行截图




qiniulive.jpg
本文暂无评论,快来抢沙发!