uniapp远程摄像头流界面上显示

用到的插件:dplayer、hls

dplayer官网:dplayer

dplayer官网npm安装的是最新版本(1.27.1),真机运行异常了,可以安装历史版本 dplayer历史版本

远程摄像头视频流格式:m3u8

可以用来测试的视频流(有的用不了,多试几个,找可以用的):m3u8测试视频

安装hls,任选其一
npm安装
下载hls文件

安装dplayer

使用 npm:

bash 复制代码
npm install dplayer --save

使用 Yarn:

bash 复制代码
yarn add dplayer

代码示例

javascript 复制代码
<template>
	<view class="containerLayout">
		<div id="dplayer"></div>
	</view>
</template>

<script>
//先加载hls插件、再加载dplayer插件;
import '/pages/utils/hls.js'
import Dplayer from 'dplayer'
	export default {
		data() {
			return {
				videoSrc: 'http://220.161.87.62:8800/hls/0/index.m3u8',
				dp: null,
			}
		},
		onLaunch() {
			console.log('onLaunch')
		},
		onReady() {
			
		},
		mounted() {
			//data里的远程摄像头地址
			const vs = this.videoSrc
			
			this.dp = new Dplayer({
				container: document.getElementById('dplayer'),
				autoplay: true, //是否自动播放
				loop: true,//视频是否循环播放
				lang: 'zh-cn',
				live: true,
				screenshot: false,//是否开启截图
				hotkey: true,//是否开启热键
				preload: 'auto',//视频是否预加载
				volume: 0.7,//默认音量
				mutex: true,//阻止多个播放器同时播放,当前播放器播放时暂停其他播放器
				video: {
					url: vs, //视频地址
					type: 'customHls',
					customType: {
						customHls: function(video, player) {
							const hls = new Hls()  //实例化Hls  解析m3u8
							hls.loadSource(video.src)
							hls.attachMedia(video)
						}
					},
				 },
			 });
			 this.dp.on('canplay', function() {
			 	console.log('视频正常播放')
			 });
			 this.dp.on('error', function() {
			 	console.log('视频播放异常')
			 });

			
		},
		onLoad() {
			
		},
		
		onShow() {
		},
		
		methods: {
			
			playvideo(vs){
			},
			//----------------------------
			
		}
		
	}
</script>
<style>
	.containerLayout{
		margin: 0;
		padding: 0;
		border: 0;
		width: 100vw;
		height: 100vh;
		display: flex;
		flex-direction: column;
		z-index: 100;
	}
</style>
相关推荐
00后程序员张19 小时前
对比 Ipa Guard 与 Swift Shield 在 iOS 应用安全处理中的使用差异
android·开发语言·ios·小程序·uni-app·iphone·swift
00后程序员张1 天前
在 iOS 设备上同时监控 CPU、GPU 与内存的方法
android·ios·小程序·https·uni-app·iphone·webview
游戏开发爱好者81 天前
在 Windows、Linux 与 CI 环境下命令行上传 IPA 到 App Store
linux·windows·ios·ci/cd·小程序·uni-app·iphone
码农客栈1 天前
小程序学习(十三)之请求和上传文件拦截器
小程序·uni-app
龙井>_<1 天前
uniapp“手搓”一个年月选择器模态框(兼容多端)
uni-app
web_Hsir1 天前
uniapp + vue2 + pfdjs + web-view 实现安卓、iOS App PDF预览
android·前端·uni-app
peachSoda71 天前
uniapp app使用命令行HBuilderX cli快捷打包iOS和Android
uni-app
2501_916007472 天前
跨平台 App 安全,Flutter、RN、Unity、H5 混合应用加固
android·ios·小程序·https·uni-app·iphone·webview
咕咕咕_biubiubiu2 天前
uniapp插件——原生插件开发和使用
uni-app
芋头莎莎2 天前
UNIAPP连接MQTT记录要点
uni-app