vue 播放rtmp格式的视频

安装环境:vue 2.5.16 videojs-flash: 2.1.0, vue-video-player: 4.0.6

浏览器环境: 必须允许flash 播放

main.js 引入:
import VueVideoPlayer from ‘vue-video-player’

import ‘video.js/dist/video-js.css’ //样式

import ‘vue-video-player/src/custom-theme.css’ //样式

import ‘videojs-flash’

Vue.use(VueVideoPlayer)

组件中使用:

<div class="videoBox" :style="{width:videowidth,height:videoheight}">
  <video-player class="vjs-custom-skin"
                ref="videoPlayer"
                :options="playerOptions"
                @ready="onPlayerReadied"
                @timeupdate="onTimeupdate"
  >
  </video-player>
</div>
 <script>
  export default {
    name: 'RtmpVideo',
    data() {
      return {
        initialized: false,
        currentTech: '',
        playerOptions: {
          overNative: true,
          autoplay: true,//自动播放
          controls: true,//进度条
          loop: true,//是否循环
          // fluid: true,//按流 体大小自适应
          notSupportedMessage: '此视频暂无法播放,请查看是否安装flash',//无法播放时显示的信息
          flash: {
            swf: '../../../static/VideoJS.swf'
          },
          techOrder: ['flash', 'html5'],// 兼容顺序
          sources: [// 流配置,数组形式,会根据兼容顺序自动切换
            {
              type: 'rtmp/mp4',
              src: 'rtmp://184.72.239.149/vod/&mp4:BigBuckBunny_115k.mov'
              // src:"rtmp://live.hkstv.hk.lxdns.com/live//hks"
              // src:"rtmp://10.5.0.143:1935/render/A32E1B9AE8BE4F6083702F9B41DD2030"
            },
          ],
         // poster: '../../../static/img/map.jpg',  //静止时的画面
          controlBar: {
            timeDivider: false, // 时间分割线
            durationDisplay: false, // 总时间
            progressControl: true, // 进度条
            customControlSpacer: true, // 未知
            fullscreenToggle: true // 全屏
          },

        }
      }
    },
    props:["videowidth","videoheight"],
    mounted: function () {
      //监测浏览器是否安装了flash播放器
      this.isflashFn();

    },
    methods: {
      onPlayerReadied() {
        if (!this.initialized) {
          this.initialized = true
        }
        this.$refs.videoPlayer.player.width_ = 500
      },
      // record current time
      onTimeupdate(e) {
        // console.log('currentTime', e.cache_.currentTime)
      },

    }
  }
</script>

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
### 回答1: Vue是一种流行的前端框架,它提供了强大的工具和组件,可以帮助我们构建现代化的Web应用程序。在Vue播放RTMP流而不使用Flash,我们可以使用一些现代的技术和组件。 首先,我们可以使用video.js这样的HTML5播放器库来播放RTMP流。video.js是一个功能强大且易于使用的库,它支持HTML5视频播放,并且可以扩展以支持不同的流媒体协议,包括RTMP。我们可以使用video.js的vue插件vue-video-player来在Vue应用中轻松地集成该播放器。 其次,我们可以使用hls.js库来播放RTMP流。hls.js是一个JavaScript库,它使用HTTP Live Streaming(HLS)协议来播放视频流。我们可以使用vue-hls-player这样的vue插件来在Vue中使用hls.js库。这个插件提供了一个简单的组件,可以方便地集成HLS播放器,并播放RTMP流。 最后,我们还可以使用DPlayer这样的开源视频播放器库来播放RTMP流。DPlayer是基于HTML5的视频播放器,它使用了开源的flv.js库来支持FLV格式视频流。我们可以使用vue-dplayer这样的vue插件来在Vue应用中使用DPlayer播放RTMP流。 总之,我们可以使用video.js、hls.js或DPlayer这些HTML5播放器库来在Vue应用中播放RTMP流而不使用Flash。这些库都提供了vue插件,可以轻松地与Vue应用集成。 ### 回答2: vue播放rtmp不使用flash可以采用video.js配合Hls.js插件实现。 首先在vue项目中安装video.js和hls.js插件: ```bash npm install video.js hls.js ``` 然后在组件中引入video.js的css和js文件,并创建一个video标签: ```html <template> <div> <video id="my-video" class="video-js"></video> </div> </template> <script> import videojs from 'video.js'; import 'video.js/dist/video-js.css'; import Hls from 'hls.js'; export default { mounted() { this.initPlayer(); }, methods: { initPlayer() { const options = { autoplay: true, controls: true, sources: [{ src: 'rtmp://your-rtmp-stream-url.com/live/stream-name', type: 'rtmp/mp4', }], }; const player = videojs('my-video', options); if (Hls.isSupported()) { const hls = new Hls(); hls.loadSource('http://your-hls-stream-url.com/live/stream-name.m3u8'); hls.attachMedia(player); hls.on(Hls.Events.MANIFEST_PARSED, () => { player.play(); }); } else if (player.canPlayType('rtmp/mp4')) { player.src(options.sources[0].src); player.play(); } } } } </script> ``` 以上代码在组件加载时初始化了video.js播放器,并通过options设置播放器的参数,其中source中的src填入你的rtmp流链接。然后通过Hls.js加载hls流,如果浏览器不支持hls,则fallback到rtmp播放。 最后通过mounte钩子函数调用initPlayer函数,实现播放rtmp流不使用flash的功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值