| | |
| | | <template> |
| | | <div class="rtmp-video-wrapper"> |
| | | <video ref="videoPlayer" :options="options" class="video-js"></video> |
| | | <video ref="videoPlayer" class="video-js"></video> |
| | | </div> |
| | | </template> |
| | | |
| | |
| | | import videoJs from 'video.js'; |
| | | import 'videojs-flash'; |
| | | import SWF_URL from 'videojs-swf/dist/video-js.swf'; |
| | | import loadImg from '@/assets/images/dw_bg.jpg'; |
| | | |
| | | export default { |
| | | name: "rtmpVideo", |
| | | player: "", |
| | | props: { |
| | | url: { |
| | | type: String, |
| | | default: "", |
| | | }, |
| | | }, |
| | | data() { |
| | | return { |
| | | options: { |
| | |
| | | autoplay: false, // 自动播放 |
| | | sources: [{ // 流配置,数组形式,会根据兼容顺序自动切换 |
| | | type: 'rtmp/mp4', |
| | | src: 'rtmp://58.200.131.2:1935/livetv/hunantv' // 亲测可用 |
| | | src: loadImg // 亲测可用 |
| | | }], |
| | | techOrder: ['html5', 'flash'], |
| | | flash: { |
| | | swf: SWF_URL |
| | | } |
| | | }, |
| | | }, |
| | | playFlag: false, |
| | | } |
| | | }, |
| | | watch: { |
| | | url() { |
| | | this.changeUrl(); |
| | | }, |
| | | }, |
| | | methods: { |
| | | create() { |
| | | let self = this; |
| | | // 初始化播放器 |
| | | this.$options.player = videoJs(this.$refs.videoPlayer, this.options, function onPlayerReady() { |
| | | console.log('onPlayerReady', this); |
| | | |
| | | this.on('pause', function() { |
| | | console.log('暂停播放') |
| | |
| | | }) |
| | | }); |
| | | }, |
| | | changeUrl() { |
| | | let url = this.url; |
| | | if(this.$options.player) { |
| | | let myPlayer = this.$options.player; |
| | | myPlayer.src(url); |
| | | myPlayer.load(url); |
| | | } |
| | | |
| | | }, |
| | | play() { |
| | | this.$nextTick(()=>{ |
| | | if(this.$options.player) { |
| | | this.$options.player.play(); |
| | | } |
| | | }); |
| | | |
| | | }, |
| | | dispose() { |
| | | if(this.$options.player) { |
| | |
| | | }, |
| | | mounted() { |
| | | this.create(); |
| | | console.log(this.$options.player); |
| | | }, |
| | | beforeDestroy() { |
| | | this.dispose(); |