This time I will bring you the custom player using iview's ui framework. What are the precautions for using iview's ui framework to customize the player? The following is a practical case, let's take a look.
Picture 2-Collapse the sidebar;
Picture 3: Full screen.
You need to use vue in this project, vue-video-player , I use the ui framework of iview, but the ui framework does not matter. What I focus on here is the use of vue-video-player developed based on video.js, and how to operate the API in video.js.
vue-video-player Project address: https://github.com/surmon-china/vue-video-player.
video.js document address: http://docs.videojs.com/docs/api/player.html.
Project directory:
Figure 1 As you can see, this project uses a two-column adaptive layout. The right side is the playlist with a fixed width of 500px, and the left side is the player box. The playlist box can be expanded or collapsed according to the click of the handle, and the player The box also adapts its width according to the expansion/contraction of the playlist.
(Because the recorded animation is too large to be uploaded, you can clone my program and run it to see it).
The html code structure is as follows:
##Add an excessive animation when shrinking and expanding. Here we choose to use css handwritten animation:view plain copy .transition{ transition: all 1s ease; -moz-transition: all 1s ease; -webkit-transition: all 1s ease; -o-transition: all 1s ease; } view plain copy .toLeft{ .transition; margin-right: 540px !important; } .toRight{ .transition; margin-right: 40px !important; } .toHide{ .transition; right: -500px !important; } .toShow{ .transition; right: 0px !important; } view plain copy // 播放区 .player-box{ margin-right: 540px; height: 100%; position: relative; } view plain copy //侧边信息区 .info-box{ width: 520px; height: 100%; background: transparent; position: relative; overflow: hidden; } [css] view plain copy // 内容区 .content{ background: #292929; position: relative; padding: 20px 0 20px 20px; }
view plain copy
{{playerCtrl.currentTime}}/{{playerCtrl.duration}}
The specific idea is to use the player to fill the playback area, and use position positioning to fix the custom controlBar at the bottom of the playback area. Note here The z-index of the controlBar must be large enough, otherwise it will not be visible at the top when it is full screen.
css style:view plain copy
view plain copy // 播放 play(){ this.player.play(); }, // 暂停 pause(){ this.player.pause(); }, //下一曲 nextClick(){ console.log("自定义","下一曲点击"); }, //全屏 fullScreenHandle(){ console.log("全屏"); if(!this.player.isFullscreen()){ this.player.requestFullscreen(); this.player.isFullscreen(true); }else{ this.player.exitFullscreen(); this.player.isFullscreen(false); } },
view plain copy
We can change our behavior accordingly based on these state changes UI, such as displaying a "pause" button when playing, displaying "play" and other functions when pausing.
view plain copy //时间更新 onPlayerTimeupdate(player){ this.playerCtrl.currentTime=timeUtil.secondToDate(player.currentTime()); this.playerCtrl.currentTimeInt=Math.floor(player.currentTime()); console.log("当前音量",player.volume()); },
view plain copy @on-change="progressChange"
view plain copy //进度条被拉动 progressChange(val){ this.player.currentTime(val); this.playerCtrl.currentTimeInt=val; this.playerCtrl.currentTime=timeUtil.secondToDate(val); },
拿到定点的值,然后通过player的currentTime设置跳到定点播放。
音量调节的做法跟播放进度相似:
一开始初始化的时候记得配置
view plain copy muted:false,//开始声音
来开启声音,否则静音状态下调节声音无效。
使用player.volume(val)这个api设置音量,其中val=0,表示声音off,val=1表示声音最大,0.5表示声音设置在half。
最后在app.vue/需要用到这个播放器的地方 引入自定义播放器组件即可。vue-video-player是大神基于video.js开发的适用于vue.js框架的组件,具有良好兼容性,所以我们在vue中使用这个播放器组件本质还是使用video.js,我们要更多的去了解video.js中的api并使用他。
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
The above is the detailed content of Customize the player using iview's ui framework. For more information, please follow other related articles on the PHP Chinese website!