vue/js动态更改video的source路径不起效

问题现象

在vue项目中(或各网页),当我们需要用到video控件播放视频,当需要点击其他视频图片想要在主视频区域中播放时,在项目直接更改主视频的source文件路径(直接src不存在这个问题),发现视频并没有按我们想象中那样变成另一个视频路径播放。例如,在vue项目中我们这样写:

<video>
	<source v-for="(type) in video" :key="type.id" :src="type.src" :type="'video/' + type.type"></source>
	<p>您的浏览器不支持 video 标签。</p>
</video>

data: ()=>{
   
	return {
   
		video: [
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是从零开始封装一个基于videojsVue动态source的视频播放器组件的步骤: 1. 安装video.jsvue-video-player 使用npm安装video.jsvue-video-player: ``` npm install video.js vue-video-player --save ``` 2. 创建Vue组件 在src/components目录下创建一个VideoPlayer.vue的文件,该文件包含以下内容: ```html <template> <div> <video ref="videoPlayer" class="video-js vjs-default-skin vjs-big-play-centered"></video> </div> </template> <script> import videojs from 'video.js'; import 'video.js/dist/video-js.css'; import 'vue-video-player/src/custom-theme.css'; import 'vue-video-player/src/font/font.css'; import 'vue-video-player/src/assets/video-player.css'; export default { name: 'VideoPlayer', props: { sources: { type: Array, required: true }, options: { type: Object, default: () => ({}) } }, mounted() { this.initPlayer(); }, beforeDestroy() { if (this.player) { this.player.dispose(); } }, methods: { initPlayer() { const video = this.$refs.videoPlayer; const playerOptions = Object.assign({ controlBar: { children: { playToggle: {}, progressControl: {}, remainingTimeDisplay: {}, fullscreenToggle: {} } }, sources: this.sources }, this.options); this.player = videojs(video, playerOptions, function onPlayerReady() { console.log('Player ready'); }); } } }; </script> ``` 3. 在Vue项目中使用该组件 在需要使用视频播放器的Vue组件中引入VideoPlayer组件,并传入sources和options参数: ```html <template> <div class="app"> <VideoPlayer :sources="sources" :options="options"></VideoPlayer> </div> </template> <script> import VideoPlayer from '@/components/VideoPlayer.vue'; export default { name: 'App', components: { VideoPlayer }, data() { return { sources: [ { src: 'http://example.com/path/to/video.mp4', type: 'video/mp4' } ], options: { autoplay: false, controls: true, preload: 'auto', fluid: true } }; } }; </script> ``` 这样就完成了从零开始封装一个基于videojsVue动态source的视频播放器组件。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值