uni-app集成mui-player

本文介绍了如何在uni-app项目中集成mui-player,包括静态webview的设置(指定src和参数传递),以及动态创建webview的详细步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

uni-app集成mui-player,仅说明集成方法,mui-player 相关配置请查看其官网

准备
  1. 在uniapp项目根目录新建hybrid目录
  2. 在hybrid目录下新建html目录
  3. 在html目录中新建css、js、img等目录,用于存放相关文件
集成
静态webview
  1. 在pages目录下新建vue页面
  2. 在vue文件中使用webview
  3. webview的src为/hybrid/html/muiplayer.html,这里的html文件要写你自己的文件名
  4. 如果要传参,src为/hybrid/html/muiplayer.html?p=123
  5. 在muiplayer.html页面中用js来获取参数p
动态创建webview

详细代码请查看我都另一边文章

2024.03.21 uniapp播放m3u8视频【mui-player插件】拂晓东夕已于 2024-04-17 16:14:04 修改阅读量2.4k 收藏 17点赞数 14文章标签: uni-app 音视频版权uniapp播放m3u8视频uniapp 官方提供了video,对于MP4格式的视频支持,现有需求查看实时视频,m3u8格式的视频流,不支持。网上看了很多插件,在插件市场找到了 mui-player插件,本插件目前免费 感谢作者插件地址https://ext.dcloud.net.cn/plugin?id=16104官方文档https://muiplayer.js.org/zh/guide/使用导入可演示demo,将demo中的node_modules文件夹下的 hls.js文件夹 mui-player文件夹导入自己项目的同级目录下,再在展示视频的地方进行实例化配置即可核心代码<div id="mui-player"></div>import 'mui-player/dist/mui-player.min.css'import Hls from 'hls.js'import MuiPlayer from 'mui-player'data(){ return { videoPlay:null, }}mounted() { this.videoPlay = new MuiPlayer({ container: '#mui-player', title: "标题", src: "http://60.163.137.66:9092/openUrl/cRq7nP2/live.m3u8", // poster: this.poster, width: 300, height: 150, preload:"auto", objectFit: "contain", pageHead: false, showMiniProgress: true, autoFit: false, videoAttribute: [ { attrKey: 'webkit-playsinline', attrValue: 'webkit-playsinline' }, { attrKey: 'playsinline', attrValue: 'playsinline' }, { attrKey: 'x5-video-player-type', attrValue: 'h5-page' } ], parse: { type: 'hls', loader: Hls, config: { debug: false } }, })},// 视频流及时销毁onUnload (){ if(this.videoPlay != null){ this.videoPlay.destroy() }},123456789101112131415161718192021222324252627282930313233343536373839404142434445具体的配置可查看官方文档,APP打包自测。2024-04-10 更改因上述方式适合用于H5,APP不支持,改变实现方式,使用HTML5+ 提供的调用原生控件,打包须勾选相应模块权限initVideo() { // #ifdef APP-PLUS // 创建视频播放控件 // if (!this.player) { this.player = plus.video.createVideoPlayer('mui-player', { src: this.videoUrl, top: '100px', left: '0px', width: '100%', height: '300px', position: 'static' }); const currentWebview = this.$mp.page.$getAppWebview(); currentWebview.append(this.player) this.player.play() // 打开即全屏 this.player.requestFullScreen() // 监听全屏退出事件 this.player.addEventListener("fullscreenchange", (e) => { // if(this.player.isFullScreen()){ // this.player.exitFullScreen() // } if (this.player) { this.player.close() } }) // #endif },
03-22
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值