基于vue-element組件實(shí)現(xiàn)音樂(lè)播放器功能
最近在寫(xiě)一個(gè)基于 github-page 和 gist 的博客, 想加個(gè)音樂(lè)播放器, 做了一個(gè)早上, 發(fā)出來(lái)分享一下
演示地址 https://github-laziji.github.io
效果

使用到的組件
element組件
- 布局 Layout
- 按鈕 Button
- 滑塊 Slider
- 進(jìn)度條 Progress
- 彈出框 Popover
html5組件
audio
實(shí)現(xiàn)代碼
更詳細(xì)的實(shí)現(xiàn)可以看 https://github.com/GitHub-Laziji/vblog
<template>
<div>
<el-row>
<el-col :span="4">
<el-popover
placement="top-start"
trigger="hover">
<div style="text-align: center">
<el-progress
color="#67C23A"
type="circle"
:percentage="music.volume"></el-progress><br>
<el-button
@click="changeVolume(-10)"
icon="el-icon-minus"
circle></el-button>
<el-button
@click="changeVolume(10)"
icon="el-icon-plus"
circle></el-button>
</div>
<el-button
@click="play"
id="play"
slot="reference"
:icon="music.isPlay?'el-icon-refresh':'el-icon-caret-right'"
circle></el-button>
</el-popover>
</el-col>
<el-col :span="14" style="padding-left: 20px">
<el-slider
@change="changeTime"
:format-tooltip="formatTime"
:max="music.maxTime"
v-model="music.currentTime"
style="width: 100%;"></el-slider>
</el-col>
<el-col :span="6" style="padding: 9px 0px 0px 10px;color:#909399;font-size: 13px">
{{formatTime(music.currentTime)}}/{{formatTime(music.maxTime)}}
</el-col>
</el-row>
<audio ref="music" loop autoplay>
<source src="http://sc1.111ttt.cn:8282/2018/1/03m/13/396131232171.m4a?tflag=1519095601&pin=6cd414115fdb9a950d827487b16b5f97#.mp3" type="audio/mpeg">
</audio>
</div>
</template>
<script>
export default{
data(){
return {
music:{
isPlay:false,
currentTime:0,
maxTime:0,
volume:100
}
}
},
mounted(){
this.$nextTick(()=>{
setInterval(this.listenMusic,1000)
})
},
methods:{
listenMusic(){
if(!this.$refs.music){
return
}
if(this.$refs.music.readyState){
this.music.maxTime = this.$refs.music.duration
}
this.music.isPlay=!this.$refs.music.paused
this.music.currentTime = this.$refs.music.currentTime
},
play(){
if(this.$refs.music.paused){
this.$refs.music.play()
}else{
this.$refs.music.pause()
}
this.music.isPlay=!this.$refs.music.paused
this.$nextTick(()=>{
document.getElementById('play').blur()
})
},
changeTime(time){
this.$refs.music.currentTime = time
},
changeVolume(v){
this.music.volume += v
if(this.music.volume>100){
this.music.volume = 100
}
if(this.music.volume<0){
this.music.volume = 0
}
this.$refs.music.volume = this.music.volume/100
},
formatTime(time){
let it = parseInt(time)
let m = parseInt(it/60)
let s = parseInt(it%60)
return (m<10?"0":"")+parseInt(it/60)+":"+(s<10?"0":"")+parseInt(it%60)
}
}
}
</script>
總結(jié)
以上所述是小編給大家介紹的基于vue-element組件實(shí)現(xiàn)音樂(lè)播放器功能,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)歡迎給我留言,小編會(huì)及時(shí)回復(fù)大家的!
- Vue3實(shí)現(xiàn)簡(jiǎn)易音樂(lè)播放器組件
- vue仿網(wǎng)易云音樂(lè)播放器界面的簡(jiǎn)單實(shí)現(xiàn)過(guò)程
- Vue.js實(shí)現(xiàn)音樂(lè)播放器
- Vue 開(kāi)發(fā)音樂(lè)播放器之歌手頁(yè)右側(cè)快速入口功能
- vue一個(gè)頁(yè)面實(shí)現(xiàn)音樂(lè)播放器的示例
- vue音樂(lè)播放器插件vue-aplayer的配置及其使用實(shí)例詳解
- 基于vue-video-player自定義播放器的方法
- vue-video-player視頻播放器使用配置詳解
- vue-music關(guān)于Player播放器組件詳解
- vue實(shí)現(xiàn)簡(jiǎn)易音樂(lè)播放器
相關(guān)文章
Vue3狀態(tài)管理之Pinia的入門(mén)使用教程
Pinia是Vue.js的輕量級(jí)狀態(tài)管理庫(kù),比起vue3中的Vuex狀態(tài)管理,pinia更輕量,更容易使用,下面這篇文章主要給大家介紹了關(guān)于Vue3狀態(tài)管理之Pinia的入門(mén)使用教程,需要的朋友可以參考下2022-04-04
vue實(shí)現(xiàn)的上拉加載更多數(shù)據(jù)/分頁(yè)功能示例
這篇文章主要介紹了vue實(shí)現(xiàn)的上拉加載更多數(shù)據(jù)/分頁(yè)功能,涉及基于vue的事件響應(yīng)、數(shù)據(jù)交互等相關(guān)操作技巧,需要的朋友可以參考下2019-05-05
vue項(xiàng)目實(shí)現(xiàn)m3u8流媒體播放詳細(xì)圖文教程
m3u8是一種常用的視頻流媒體格式,通常用于在Web上播放視頻,這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目實(shí)現(xiàn)m3u8流媒體播放的相關(guān)資料,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-09-09
VUE中v-on:click事件中獲取當(dāng)前dom元素的代碼
這篇文章主要介紹了VUE中v-on:click事件中獲取當(dāng)前dom元素的代碼,文中同時(shí)給大家提到了v-on:click獲取當(dāng)前事件對(duì)象元素的方法,需要的朋友可以參考下2018-08-08
解決element ui el-row el-col里面高度不一致問(wèn)題
這篇文章主要介紹了解決element ui el-row el-col里面高度不一致問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-08-08
基于Vue實(shí)現(xiàn)HTML轉(zhuǎn)PDF并導(dǎo)出
這篇文章主要為大家介紹了三種方法,可以實(shí)現(xiàn)將HTML頁(yè)面轉(zhuǎn)為PDF并實(shí)現(xiàn)下載。文中的示例代碼講解詳細(xì),感興趣的小伙伴可以學(xué)習(xí)一下2022-04-04
element表單el-form的label自適應(yīng)寬度的實(shí)現(xiàn)
本文主要介紹了element表單el-form的label自適應(yīng)寬度的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
vue3的watch用法以及和vue2中watch的區(qū)別
這篇文章主要介紹了vue3的watch用法以及和vue2中watch的區(qū)別,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04

