uniapp实现直播的方法:首先通过推流,代码为【开始推流】;然后使用video标签实现拉流即可。

本教程操作环境:windows7系统、uni-app2.5.1版本,该方法适用于所有品牌电脑。

uniapp实现直播的方法:

1、推流

id="livePusher"

ref="livePusher"

class="livePusher"

url="" **这里需要请求后端接口,拿到推流地址**

mode="SD"

:muted="true"

:enable-camera="true"

:auto-focus="true"

:beauty="1"

whiteness="2"

aspect="9:16"

@statechange="statechange"

@netstatus="netstatus"

@error="error"

>

开始推流

暂停推流

resume

停止推流

快照

开启摄像头预览

关闭摄像头预览

切换摄像头

去播放

export default {

data() {

return {

context:[]

};

},

onReady() {

// 注意:需要在onReady中 或 onLoad 延时

this.context = uni.createLivePusherContext('livePusher', this);

},

methods: {

statechange(e) {

console.log('statechange:' + JSON.stringify(e));

},

netstatus(e) {

console.log('netstatus:' + JSON.stringify(e));

},

error(e) {

console.log('error:' + JSON.stringify(e));

},

start(){

this.context.start({

success: a => {

console.log('livePusher.start:' + JSON.stringify(a));

},

error:err=>{

console.log(err)

}

});

},

close() {

this.context.close({

success: a => {

console.log('livePusher.close:' + JSON.stringify(a));

}

});

},

snapshot() {

this.context.snapshot({

success: e => {

console.log(JSON.stringify(e));

}

});

},

resume() {

this.context.resume({

success: a => {

console.log('livePusher.resume:' + JSON.stringify(a));

}

});

},

pause() {

this.context.pause({

success: a => {

console.log('livePusher.pause:' + JSON.stringify(a));

}

});

},

stop() {

this.context.stop({

success: a => {

console.log(JSON.stringify(a));

}

});

},

switchCamera() {

this.context.switchCamera({

success: a => {

console.log('livePusher.switchCamera:' + JSON.stringify(a));

}

});

},

startPreview() {

this.context.startPreview({

success: a => {

console.log('livePusher.startPreview:' + JSON.stringify(a));

}

});

},

stopPreview() {

this.context.stopPreview({

success: a => {

console.log('livePusher.stopPreview:' + JSON.stringify(a));

}

});

},

bofang(){

this.$u.route({

url: 'pages/index/index'

})

}

}

};

.content {

display: flex;

flex-direction: column;

align-items: center;

justify-content: center;

}

.logo {

height: 200rpx;

width: 200rpx;

margin-top: 200rpx;

margin-left: auto;

margin-right: auto;

margin-bottom: 50rpx;

}

.text-area {

display: flex;

justify-content: center;

}

.title {

font-size: 36rpx;

color: #8f8f94;

}

**

2、拉流

这里是app拉流,用的是video标签,代码如下

export default {}

src是请求接口得到的拉流地址相关免费学习推荐:php编程(视频)

uniapp怎么调起摄像头拍视频_uniapp如何实现直播相关推荐

  1. uniapp怎么调起摄像头拍视频_uniapp实现简单直播功能

    uniapp实现简单的直播功能其实很简单,因为uniapp本身就集成了一个api,直播主要有两点,推流拉流,下面是实现代码 1.推流 id="livePusher" ref=&qu ...

  2. uniapp怎么调起摄像头拍视频_uni-app实现图片和视频上传功能

    var sourceType =[ ['camera'], ['album'], ['camera', 'album'] ] exportdefault{ data() {return{ imageL ...

  3. uniapp怎么调起摄像头拍视频_抖音视频怎么拍?我们总结了10个手机视频拍摄小技巧...

    抖音的很多功能与小咖秀类似,但不同的是,抖音用户可以通过视频拍摄的快慢.视频编辑和特效等技术让作品更具创造性,而不是简单地对嘴型. 抖音短视频的10个拍摄技巧,帮助你方便.快捷地制作出更加优质的短视频 ...

  4. 解决微信企业号和公众号无法调用摄像头拍视频的问题

    一直以来在微信里面始终无法用<input id="videofile" name="videofile" type="file"  a ...

  5. php微信调用摄像头拍视频,公众号调用摄像头录制视频

    公众号微信网页调用摄像头录制视频,不想用input方法.  找了很久找到了腾讯优图.活体检测示例(http://open.youtu.qq.com/h5_ctl/living_detect),这里面采 ...

  6. uniapp webview 直接调用原生摄像头拍照 拍视频 img video,通过ajax获取blob(file为特殊的blob)对象并上传到后端服务器

    web-view中通过plus方法调用摄像头拍照或者拍视频并上传后端的操作步骤如下 plus.camera.getCamera()获取摄像头对象 cmr cmr.captureImage(callba ...

  7. uniapp打开摄像头进行视频并拍照

    引用 引用插件: 基于内置H5的人脸所识别组件. 引用文章:前端网页打开摄像头并将图像传给后端. 新建hybrid文件 提示:以下是本篇文章正文内容,下面案例可供参考 一.使用步骤 1.创建hybri ...

  8. vue用input调起手机摄像头录制视频

    <input ref="inputVideo" type="file" name="video" id="video-inp ...

  9. AVFoundation 视频常用套路: 拍照聚焦、曝光、闪光灯,拍视频手电筒

    看图可知, AVFoundation 拍照功能的中心类是 AVCaptureSession 类,管理视频输入输出流. 音视频,上手就用,直接 AVKit 更加灵活的控制,就用到 AVFoundatio ...

最新文章

  1. 赢得高薪的锦囊三秘诀
  2. Linux Kernel TCP/IP Stack — L1 Layer — tcpdump 抓包
  3. Servlet服务器搭建过程中一些经验 Tomcat+Mysql数据库+http传输
  4. 委派模式与策略模式综合应用
  5. Silverlight 4 Beta正式发布
  6. 2020蓝桥杯省赛---java---B---7(分类计数)
  7. jq设置保留两位小数_如何实现python中format函数保留指定位数的小数?
  8. Java:数组排序输出
  9. 云服务器一般选什么系统,云服务器一般选择什么系统好
  10. app测试的过程和重点关注内容
  11. python连接ssh_使用Python连接到SSH
  12. [ssh] remote host key has changed
  13. CustomValidator 的客户端验证
  14. win10最常用dos命令以及win+R即可运行的命令
  15. Word文档《Document SAFER 2》
  16. 李晨 | 无人机市场浅析
  17. 2021年广东省安全员A证第三批(主要负责人)考试内容及广东省安全员A证第三批(主要负责人)新版试题
  18. 基于Python的人脸识别
  19. MySQL导入northwind数据库完全手册
  20. 互联网摸鱼日报(2022-10-28)

热门文章

  1. Android模拟键盘输入功能的实现
  2. elaticsear学习常见错误
  3. JDK各个版本安装以及配置,超详细
  4. 免安装版jdk的配置及使用(附绿色版jdk1.7及jdk1.8)
  5. css日落_如何拍摄好日落照片
  6. Unity Shader 扇形进度条
  7. 为公寓运营商提供SaaS管理系统,寓小二获贝壳找房5000万元A轮融资...
  8. jellyfin 字幕方框问题
  9. 笔记本电脑怎么录音?电脑专业录音软件下载
  10. Docker、CentOS 8遭弃用,GPT-3、M1芯片撼动技术圈,盘点2020影响开发者的十大事件!...