利用Vue實(shí)現(xiàn)簡(jiǎn)易播放器的完整代碼
看b站某馬學(xué)習(xí),實(shí)現(xiàn)一個(gè)屬于自己的播放器

HTML+CSS+JS
<section id="xwyy">
<!--主體區(qū)域-->
<section class="box" style="margin-top: 30px;">
<div class="nav">
<div class="nava">
<h1>小王音樂(lè)</h1>
</div>
<!--搜索框-->
<div class="navb">
<input type="text" autocomplete="off" v-model.lazy="query" @keyup.enter="searchMusic" placeholder="搜索想聽(tīng)的歌" />
</div>
</div>
<div class="boxa">
<!--歌曲列表-->
<div class="boxa1">
<ul>
<li v-for="item in musicList">
<a href="#" @click="playMusic(item.id)" class="iconfont icon-bofang1"></a>
<label>{{item.name}}</label>
<a href="#" v-if="item.mvid!=0" @click="playMv(item.mvid)" class="iconfont icon-MV"> </a>
</li>
</ul>
</div>
<!--歌曲信息-->
<div class="boxa2" :class="{playing:isPlayin}">
<img src="img/cd1.png" class="imga" />
<img src="img/cd.png" class="imgb autoRotate" />
<img :src="musicCover" class="imgc autoRotate" />
</div>
<!--歌曲評(píng)論-->
<div class="boxa3">
<h1>熱門評(píng)論</h1>
<div class="boxa3_nr" v-for="item in hotComments">
<div class="boxa3_nr1">
<img :src="item.user.avatarUrl" />
</div>
<div class="boxa3_nr2">
<h3>{{item.nickname}}</h3>
<div class="a3p">
{{item.content}}
</div>
</div>
</div>
</div>
</div>
<!--播放音樂(lè)-->
<div class="boxb">
<audio :src="musicUrl" @play="play" @pause="pause" controls autoplay loop>
</audio>
</div>
<div class="mv" v-show="isShow">
<video ref='video' :src="mvUrl" width="100%" height="100%" controls="controls">
</video>
</div>
<div class="mk" @click="hide" v-show="isShow">
</div>
</section>
</section>
* {
margin: 0;
padding: 0;
font-size: 12px;
}
ul {
list-style: none;
}
body {
background-image: url(../img/acg.jpg);
background-size: 100%;
position: relative;
}
.box {
width: 1000px;
height: 570px;
background-color: rgba(205, 205, 205, 0.4);
margin: 0 auto;
position: relative;
}
.nav {
width: 100%;
height: 50px;
display: flex;
justify-content: space-between;
align-items: center;
box-sizing: content-box;
background-image: linear-gradient(to bottom right, #e66465, #9198e5);
/*漸變*/
}
.nav h1 {
padding-left: 20px;
color: #fff;
font-size: 16px;
}
.navb {
width: 230px;
height: 25px;
background-color: rgba(0, 0, 0, 0.3);
border-radius: 10px;
display: flex;
align-items: center;
overflow: hidden;
margin-right: 20px;
}
.navb input {
width: 80%;
border: 0px;
box-sizing: border-box;
background-color: rgba(0, 0, 0, 0);
margin-left: 10px;
font-size: 12px;
color: #fff;
outline: none/*去掉聚焦框*/
}
/*改變input中placeholder的顏色*/
.navb input::-ms-input-placeholder {
color: silver;
}
.navb input::-webkit-input-placeholder {
color: silver;
}
.boxa {
width: 100%;
min-height: 500px;
box-sizing: content-box;
display: flex;
justify-content: space-between;
}
.boxa1 {
width: 250px;
height: 500px;
display: flex;
justify-content: center;
border-right: 2px solid rgba(205, 205, 205, 0.3);
overflow-x: hidden;
scrollbar-width: none;
/*兼容火狐*/
-ms-overflow-style: none;
/*兼容IE*/
}
.boxa1::-webkit-scrollbar {
/*兼容谷歌*/
display: none;
}
.boxa1 a {
display: block;
width: 15px;
height: 15px;
/*background-image: url(../img/bf.jpg);
background-size:100% ;*/
text-decoration: none;
color: red;
}
.boxa1 i {
display: block;
width: 15px;
height: 15px;
background-image: url(../img/2.png);
}
.boxa1 li {
display: flex;
justify-content: space-between;
align-items: center;
width: 210px;
padding: 5px;
margin-top: 10px;
/*background-color: rgba(0,0,0,0.2);*/
color: #000;
}
.boxa1 label {
margin-left: 20px;
margin-right: 25px;
}
.boxa1 li:nth-of-type(2n+1) {
background-color: rgba(0, 0, 0, 0.2);
color: #fff;
}
.boxa2 {
width: 500px;
height: 500px;
border-right: 1px solid rgba(205, 205, 205, 0.3);
display: flex;
justify-content: center;
position: relative;
overflow: hidden;
}
.boxa3 {
width: 250px;
height: 500px;
position: relative;
overflow-x: hidden;
scrollbar-width: none;
/*兼容火狐*/
-ms-overflow-style: none;
/*兼容IE*/
}
.boxa3::-webkit-scrollbar {
/*兼容谷歌*/
display: none;
}
.boxa3 h1 {
position: absolute;
top: 5px;
left: 40%;
}
.boxa3_nr {
width: 260px;
height: ;
margin-top: 30px;
overflow: hidden;
margin-left: 20px;
}
.boxa3_nr1 {
width: 50px;
height: 50px;
float: left;
overflow: hidden;
border-radius: 50px;
}
.boxa3_nr2 {
width: 150px;
height: ;
margin-left: 10px;
float: left;
overflow: hidden;
}
.boxa3_nr2 h3 {
font-size: 15px;
}
.clear {
clear: left;
}
.a3p {
width: 150px;
height: ;
margin-top: 5px;
}
.boxa3 img {
width: 100%;
height: 100%;
}
.boxb {
width: 100%;
height: 40px;
background-color: aliceblue;
}
.boxb audio {
width: 100%;
height: 100%;
}
/*是否正在播放*/
.boxa2.playing .imgb,
.boxa2.playing .imgc {
animation-play-state: running;
}
/*桿*/
.boxa2.playing .imga {
transform: rotate(45deg);
transition: .5s;
}
@keyframes Rotate {
from {
transform: rotateZ(0);
}
to {
transform: rotateZ(360deg);
}
}
/*旋轉(zhuǎn)的類名*/
.autoRotate {
animation-name: Rotate;
animation-iteration-count: infinite;
animation-play-state: paused;
animation-timing-function: linear;
animation-duration: 5s;
}
.imga {
display: block;
width: 120px;
height: 60px;
position: absolute;
top: -5px;
right: 100px;
z-index: 3;
transform: rotate(0);
transform-origin: 12px 12px;
transition: .5s;
}
.imgb {
display: block;
width: 300px;
height: 300px;
margin-top: 50px;
position: relative;
}
.imgc {
display: block;
width: 220px;
height: 220px;
position: absolute;
top: 19%;
left: 29%;
z-index: -2;
border-radius: 100px;
}
.mv {
width: 1000px;
height: 600px;
position: absolute;
background-color: #000;
top: 0;
left: 0;
z-index: 7;
}
.mk {
width: 1000px;
height: 600px;
position: absolute;
top: 0;
left: 0;
transform: scale(6);
background-color: rgba(0, 0, 0, 0.7);
z-index: 5;
}
.mv video {
width: 100%;
height: 100%;
padding: 0px;
margin: 0px;
}
var xwyy = new Vue({
el:"#xwyy",
data:{
query:"",
musicList:[],
musicUrl:"",
musicCover:"",
hotComments:[],
isPlayin:false,
isShow:false,
mvUrl:""
},
methods:{
/*歌曲搜索*/
searchMusic:function(){
var that = this;
axios.get("https://autumnfish.cn/search?keywords="+this.query)
.then(function(response){
that.musicList = response.data.result.songs;
},function(err){});
},
/*歌曲播放*/
playMusic:function(muiscId){
var that = this;
/*獲取歌曲地址*/
axios.get("https://autumnfish.cn/song/url?id="+muiscId)
.then(function(response){
that.musicUrl = response.data.data[0].url;
},function(err){})
/*獲取歌曲圖片*/
axios.get("https://autumnfish.cn/song/detail?ids="+muiscId)
.then(function(response){
that.musicCover = response.data.songs[0].al.picUrl;
},function(err){})
/*獲取歌曲評(píng)論*/
axios.get("https://autumnfish.cn/comment/hot?type=0&id="+muiscId)
.then(function(response){
that.hotComments = response.data.hotComments;
},function(err){})
},
/*播放*/
play:function(){
this.isPlayin = true;
},
/*暫停*/
pause:function(){
this.isPlayin = false;
},
playMv:function(mvid){
var that = this;
axios.get("https://autumnfish.cn/mv/url?id="+mvid)
.then(function(response){
that.isShow = true;
that.mvUrl = response.data.data.url;
},function(err){})
},
/*隱藏mv*/
hide:function(){
this.isShow = false;
/*關(guān)閉mv*/
this.$refs.video.pause();
}
}
});
總結(jié)
到此這篇關(guān)于利用Vue實(shí)現(xiàn)簡(jiǎn)易播放器的文章就介紹到這了,更多相關(guān)Vue實(shí)現(xiàn)簡(jiǎn)易播放器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 基于vue-video-player自定義播放器的方法
- vue一個(gè)頁(yè)面實(shí)現(xiàn)音樂(lè)播放器的示例
- vue音樂(lè)播放器插件vue-aplayer的配置及其使用實(shí)例詳解
- vue-music關(guān)于Player播放器組件詳解
- vue實(shí)現(xiàn)自定義H5視頻播放器的方法步驟
- 基于vue-element組件實(shí)現(xiàn)音樂(lè)播放器功能
- vue-dplayer 視頻播放器實(shí)例代碼
- vue-video-player視頻播放器使用配置詳解
- 適用于 Vue 的播放器組件Vue-Video-Player操作
- Vue 開(kāi)發(fā)音樂(lè)播放器之歌手頁(yè)右側(cè)快速入口功能
相關(guān)文章
vue全局掛載實(shí)現(xiàn)APP全局彈窗的示例代碼
本文主要介紹了vue全局掛載實(shí)現(xiàn)APP全局彈窗的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
vue-baidu-map實(shí)現(xiàn)區(qū)域圈線和路徑的漸變色
這篇文章主要介紹了vue-baidu-map實(shí)現(xiàn)區(qū)域圈線和路徑的漸變色方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-07-07
Vue Element校驗(yàn)validate的實(shí)例
這篇文章主要介紹了Vue Element校驗(yàn)validate的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-09-09
使用Vue.js和Flask來(lái)構(gòu)建一個(gè)單頁(yè)的App的示例
本篇文章主要介紹了使用Vue.js和Flask來(lái)構(gòu)建一個(gè)單頁(yè)的App的示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-03-03
vue中watch監(jiān)聽(tīng)不到變化的解決
本文主要介紹了vue中watch監(jiān)聽(tīng)不到變化的解決,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01
vue使用百度地圖報(bào)錯(cuò)BMap?is?not?defined問(wèn)題及解決
這篇文章主要介紹了vue使用百度地圖報(bào)錯(cuò)BMap?is?not?defined問(wèn)題及解決,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-10-10
Vue3如何獲取proxy對(duì)象的值而不是引用的方式
這篇文章主要介紹了Vue3如何獲取proxy對(duì)象的值而不是引用的方式,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-10-10

