vue实现音乐播放器

通过vue与原生js实现音乐播放器

下面是需要的网址

1.歌曲搜索接口
    请求地址:https://autumnfish.cn/search
    请求方法:get
    请求参数:keywords(查询关键字)
    响应内容:歌曲搜索结果
2.歌曲url获取接口
    请求地址:https://autumnfish.cn/song/url
    请求方法:get
    请求参数:id(歌曲id)
    响应内容:歌曲url地址
3.歌曲详情获取
    请求地址:https://autumnfish.cn/song/detail
    请求方法:get
    请求参数:ids(歌曲id)
    响应内容:歌曲详情(包括封面信息)
4.热门评论获取
       请求地址:https://autumnfish.cn/comment/hot?type=0
    请求方法:get
    请求参数:id(歌曲id,地址中的type固定为0)
    响应内容:歌曲的热门评论
5.mv地址获取
    请求地址:https://autumnfish.cn/mv/url
    请求方法:get
    请求参数:id(mvid,为0表示没有mv)
    响应内容:mv的地址

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title>音乐播放器</title>

    <style>

       body,ul,li,h3{

        padding:0;

        margin:0;

       }

       #app{

        width: 900px;

        margin: 30px auto 0 auto;

        /*border: 1px solid red;*/

        /*position: relative;*/

       }

        h1{

        text-align: center;

        color:red;

       }

      .search{

        background-color: blue;

        overflow: hidden;

        height: 35px;

      }

      .search>h3{

        float: left;

        color: #fff;

        line-height: 35px;

        margin-left: 10px;

      }

      .search>.right{

        position: relative;

        width: 200px;

        float: right;

        border-radius: 8px;

        background-color: #eee;

        padding:0 10px;

        margin-top: 6px;

        margin-right: 10px;

       

      }

      .search>.right>input{

        width:142px;

        border: none;

        outline: none;

        background-color: transparent;

        font-size: 12px;

      }

      .search>.right>button{

        position: absolute;

        border: none;

        background-color: transparent;

        font-size:12px;

        padding-bottom:3px;

        cursor: pointer;

      }

      .show{

        height: 382px;

      }

      .show>.left{

        width: 200px;

        height: 374px;

        padding-top:8px;

        padding-left: 10px;

        padding-right: 10px;

        overflow:auto;

        float: left;

      }

      ul{

        list-style: none;

      }

      .show>.left>ul>li{

        line-height: 24px;

        border-bottom: 1px dashed #999;

        font-size: 12px;

        letter-spacing:-1.5px;

      }

      .show>.left>ul>li:hover{

        background-color: orange !important;

      }

       .show>.left>ul>li:last-child{

        border:none;

       }

       .show>.left>ul>li:nth-child(2n){

        background-color: #E3FAFC;

       }

      .show>.left>ul>li>a{

        display: inline-block;

        margin-right:2px;

        width:12px;

        height:12px;

        background-image: url("images/play.png");

        background-size: 12px;

      }

      .show>.left>ul>li>img{

        width: 12px;

        height: 12px;

        float: right;

        margin-top: 6px;

        cursor: pointer;

      }

      .show>.middle{

        position: relative;

        float: left;

        width: 400px;

        height: 382px;

        background-color: #E8FCFC;

        text-align: center;

      }

      .show>.middle>img{

        position: absolute;

        width:200px;

        height:200px;

        border-radius: 50%;

        /* margin-top:50px;

        margin-right: 20px; */

        top:110px;

        right: 100px;

      }

      .playing{

        animation: rotate 8s linear infinite;

      }

      @keyframes rotate {

        from {

          transform: rotateZ(0);

        }

        to {

          transform: rotateZ(360deg);

        }

      }

      .show>.right{

        position: relative;

        float: right;

        width: 280px;

        height: 382px;

        /*background-color: pink;*/

        padding:5px 0px 5px 5px;

        box-sizing: border-box;

        overflow:auto;

      }

      .show>.right>h5{

        margin:0;

        text-align: center;

        padding-bottom:3px;

      }

      .show>.right>ul>li{

        padding:3px 0 10px 0;

        border-top: 1px dashed #ccc;

      }

      .show>.right>ul>li>img{

        width:40px;

        height:40px;

        border-radius: 50%;

        float: left;

      }

      .show>.right>ul>li>p{

        margin:0;

        margin-left:45px;

        font-size: 12px;

        letter-spacing:-1.5px;

      }

      .show>.right>ul>li>p.name{

        font-weight: bold;

      }

      audio{

        width: 900px;

        height: 34px;

      }

      div.video_dd{

        width: 100%;

        height:1500px;

        padding-top: 30px;

        position: absolute;

        left:0;

        top:0;

        text-align: center;

        background-color:rgba(0,0,0);

        display: none;

      }

      video{

        width: 900px;

        height: 550px;

      }

      #lv{

        font-size: 25px;

        font-weight: 100;

      }

    </style>

</head>

<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

<script src="vue-2.7.14.js"></script>

<body>

<div id="app">

      <h1>音乐播放器</h1>

     <!-- 搜索歌曲 -->

       <div class="search">

          <h3>悦听</h3>

          <div class="right" @keydown.enter="sousuo">

             <input type="text" v-model="gequ">

             <button type="button" @click="sousuo">搜索</button>

          </div>

       </div>

       <!-- 歌曲信息 -->

       <div class="show">

           <!-- 歌曲名称 -->

           <div class="left">

               <ul>

                  <li v-for="(item,index) in name1">

                    <a href="javascript:;"  @click="kais(musicurl[index],index)"></a>

                     <span>{{item}}-{{name2[index]}}</span>

                     <img src="images/film.png" alt="">

                  </li>

               </ul>

           </div>

           <!-- 歌曲封面 -->

           <div class="middle" >

             <p id="lv" align="center">{{gename}}</p>

              <img id="abc" :src="chushi" class="" alt="">

           </div>

           <!-- 歌曲评论 -->

           <div class="right">

             <h5>热门留言</h5>

              <ul>

                 <li v-for="(item,index) in pinglun">

                  <img :src="pingluntou[index]" alt="">

                  <p class="name">{{pinglunname[index]}}</p>

                  <p>{{pinglun[index]}}</p>

               </li>

              </ul>

           </div>

       </div>

       <!-- 播放按钮 -->

       <audio :src="tes" id="audio" οnplay="f2()" οnpause="f3()" controls></audio>

       <div class="video_dd" >

           <video src=""  controls autoplay loop></video>

       </div>

    </div>

    <script>

      // axios.defaults.baseURL="https://autumnfish.cn";

      const vm=new Vue({

        el:"#app",

        data:{

          window:window,

          gequ:'周杰伦',

          name1:[],

          id1:[],

          musicurl:[],

          name2:[],

          tes:'',

          pinglun:[],

          pingluntou:[],

          pinglunname:[],

          fengmian:[],

          chushi:'images/wf.jpg',

          play1:'',

          gename:''

        },

        methods: {

          sousuo:function(){

            var t=this;

            this.window.axios.get("https://autumnfish.cn/search?keywords=%27"+this.gequ+"%27").then(function(response)

            { t.name1.splice(0,t.name1.length)

              t.id1.splice(0,t.id1.length)

              t.musicurl.splice(0,t.musicurl.length)

              t.name2.splice(0,t.name2.length)

              t.fengmian.splice(0,t.fengmian.length)

             

              // t.touids.splice(0,t.touids.length)

              try{

              var a=response.data.result.songs.length;

              var b=response.data.result.songs;}

              catch{return}

             

              for(var i=0;i<a;i++){

                t.name1.push(b[i].name);

                t.id1.push(b[i].id);

                if(b[i].artists[0].name=="")

                t.name2.push("0")

                else t.name2.push(b[i].artists[0].name)

              }

              var z=t.name1.length;

            for(var i=0;i<z;i++)

            {

              // console.log(t.id1[i]);

                t.window.axios.get("https://autumnfish.cn/song/url?id="+t.id1[i]).then(function(response){

                  if(response.data.data[0].url!=null)

                  t.musicurl.push(response.data.data[0].url)

                  else

                  t.musicurl.push('0');

                })

            }

            for(var i=0;i<z;i++)

            {

              // console.log(t.id1[i]);

                t.window.axios.get("https://autumnfish.cn/song/detail?ids="+t.id1[i]).then(function(response){

                  console.log(response);

                  if(response.data.songs[0].al.picUrl!=null)

                  t.fengmian.push(response.data.songs[0].al.picUrl)

                  else

                  t.fengmian.push('0');

                })

            }

            });  

                 

          }

          ,kais:function(a,b){

            if(a=="0")

            {

              this.tes=""

              this.pinglun.splice(0,this.pinglun.length)

              this.pingluntou.splice(0,this.pingluntou.length)

              this.pinglunname.splice(0,this.pinglunname.length)

              this.window.document.querySelector('#abc').className =''

              this.chushi='images/wf.jpg'

              this.gename=''

              alert("please change music")

              return

            }

            var y=this;

            this.tes=a;

            this.window.axios.get("https://autumnfish.cn/comment/music?id="+this.id1[b]+"&limit=1").then(function(response){

              console.log(response);

              var x=response.data.hotComments.length

              var z=response.data.hotComments;

              y.pinglun.splice(0,y.pinglun.length)

              y.pingluntou.splice(0,y.pingluntou.length)

              y.pinglunname.splice(0,y.pinglunname.length)

              for(var i=0;i<x;i++){

               y.pinglun.push(z[i].content);

               y.pingluntou.push(z[i].user.avatarUrl)

               y.pinglunname.push(z[i].user.nickname)

              }

            })

            this.gename =this.name1[b]

            this.chushi=this.fengmian[b]

            this.window.document.querySelector('#abc').className =''

        }

        },

        go1:function(){

          this.play1='playing'

          document.querySelector('.playing').style.animationPlayState = ''

        },

      })

      function f2(){

        var tt=document.querySelector('#abc')

        tt.className='playing'

        tt.style.animationPlayState = ''

      }

      function f3(){

        var tt=document.querySelector('#abc')

        tt.className='playing'

        tt.style.animationPlayState = 'paused'

      }

    </script>

</body>

</html>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/4362.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

有人物联口红DTU DR154配置与RS 485传感器数据处理

一、硬件设备 &#xff08;1&#xff09;有人物联口红DTU DR154&#xff08;RS 485版本&#xff09; 这个DTU非常给力&#xff0c;不用插卡自带esim卡&#xff0c;送8年流量&#xff0c;配置的话通过小程序【联博士】蓝牙配置&#xff08;手机扫描DTU背后的二维码即可&#x…

界面开发框架Qt新手入门教程 - 项目视图示例介绍

Qt 是目前最先进、最完整的跨平台C开发工具。它不仅完全实现了一次编写&#xff0c;所有平台无差别运行&#xff0c;更提供了几乎所有开发过程中需要用到的工具。如今&#xff0c;Qt已被运用于超过70个行业、数千家企业&#xff0c;支持数百万设备及应用。Qt提供了许多功能&…

java基础问答

57、synchronized 各种加锁场景的作用范围 1.作用于非静态方法&#xff0c;锁住的是对象实例&#xff08;this&#xff09;&#xff0c;每一个对象实例有一个锁。 public synchronized void method() {} 2.作用于静态方法&#xff0c;锁住的是类的Class对象&#xff0c;因为Cl…

chatgpt+安全机器人控制器+底盘一体化方案设计构想

“你有没有想过&#xff0c;你只需告诉你的家庭助理机器人&#xff1a;‘请加热我的午餐’&#xff0c;它就会自己找到微波炉。这是不是很神奇&#xff1f;” 近日&#xff0c;微软在其官网发表了一篇名为《机器人 ChatGPT&#xff1a;设计原则和模型能力&#xff08;ChatGPT …

MongoDB 6.0 入门(一)

为什么研究MongDB 6.0 今天和老大聊天 聊到了一个场景的设计&#xff0c;我刚开始推荐了 clickhouse &#xff0c;然后老大指出 前两天 测试的结果&#xff0c;因为clickhouse 因为 是列式存储&#xff0c;导致我们要查询一行数据&#xff0c;需要200ms&#xff08;库中有2000…

MyBatis源码分析(二、续)SqlSource创建流程,SQL如何解析?如何将#{id}变成?的

文章目录实例一、SqlSource处理入口二、SqlSource处理逻辑1、XMLScriptBuilder 构造方法2、解析动态sql3、DynamicSqlSource4、RawSqlSource解析sql&#xff08;1&#xff09;parse方法解析sql写在后面实例 此处我们分析的sql&#xff1a; <select id"selectBlog&quo…

redis 十. 线程基础

目录一. redis 基础复习与了解redis6二. redis 线程问题总结一. redis 基础复习与了解redis6 redis官网, redis中文网站, redis命令参考网站此处以redis6.0.8或以上版本为例(查看自己redis版本命令"redis- server -v")按照redis6以上版本测试使用时,redis.conf下需要…

Baklib:企业知识管理帮助文档制作平台

在当今的商业环境中&#xff0c;企业面临着越来越多的挑战。其中之一是如何管理并传递企业内部的知识。企业知识管理的重要性不言而喻&#xff0c;它可以帮助企业更好地组织和利用内部的知识资源&#xff0c;提高生产力和竞争力。而Baklib作为一款企业知识管理&帮助文档制作…

新四级强化辅导

词汇题&#xff08;55道&#xff09; 1. You should carefully think over_____ the manager said at the meeting. A. that B. which C. what D. whose 1.选C,考察宾语从句连接词&#xff0c;主句谓语动词think over后面缺宾语&#xff0c;后面的宾语从句谓语动…

聚焦“专精特新” 共话高质量发展

3月23日&#xff0c;第七届杭州全球企业家论坛暨第三届中国专精特新企业&#xff08;新三板&#xff09;高峰论坛在杭州国博中心成功举办。超过500位专精特新企业代表、专家学者、政府部门代表、科研院所代表共聚一堂&#xff0c;现场座无虚席&#xff0c;气氛热烈。本届峰会以…

SQL Server 2016安装教程

✅作者简介&#xff1a;CSDN内容合伙人、阿里云专家博主、51CTO专家博主、新星计划第三季python赛道Top1&#x1f3c6; &#x1f4c3;个人主页&#xff1a;hacker707的csdn博客 &#x1f525;欢迎订阅系列专栏&#xff1a;SQL Server 2016从入门到精通&#x1f947; &#x1f4…

借东风拉马力,龙头券商东方财富发展持续向好

3月17日&#xff0c;互联网券商东方财富公布2022年年报。具体来看&#xff0c;东方财富2022年实现总营收124.9亿元&#xff0c;同比下滑4.6%&#xff1b;归母净利润85.1亿元&#xff0c;同比下滑0.5%&#xff0c;略低于预期。其中&#xff0c;2022年第四季度总营收同比下滑15.4…

【Python课堂】使用Akshare高效获得A股可转债的重要信息

文章目录前言一、准备二、获取基本信息1.引入库2.读入数据3.获取行情数据4.可转债比价表总结前言 Akshare是一个非常好用的开源A股数据获取模块&#xff0c;它是基于 Python 的财经数据接口库&#xff0c;目的是实现对A股、美股、期货等金融产品的基本面数据、实时和历史行情数…

【干货】交换机管理

实验目的 熟悉掌握交换机的管理&#xff0c;包括&#xff1a;密码恢复&#xff0c;IOS升级和备份&#xff0c;IOS恢复 掌握实际工程中控制线的操作 交换机管理&#xff08;一&#xff09; 交换机密码恢复&#xff08;以下实验都需要在真机上操作&#xff09; 控制线和电脑的连…

oracle语句查询时间范围

oracle语句查询时间范围 参考网址 &#xff1a; https://blog.csdn.net/weixin_36436373/article/details/116541220?ops_request_misc%257B%2522request%255Fid%2522%253A%2522167930069316800188562500%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%25…

Web自动化测试入门

1.Web自动化测试的价值&#xff08;为什么要做web自动化测试&#xff09; 我们可以使用脚本语言代替人来进行测试 2.Web自动化测试相关技术&#xff1a; Selenium:支持多语言&#xff0c;行业内最火最主流Pytest/JUnit5:最好用最全面的单元测试框架Allure:测试报告3.Web自动化…

多线程应用:定时器

一. 定时器 定时器(定时任务) 定时器是一种控制任务延时调用&#xff0c;或者周期调用的技术。作用&#xff1a;闹钟、定时邮件发送。 定时器的实现方式 方式一&#xff1a;Timer方式二&#xff1a;ScheduledExecutorService 二. Timer定时器 TimerTask继承了Runnable&#…

APT、对称加密、非对称加密、SSL工作过程技术的介绍

1. APT的简单介绍APT全称&#xff1a;Advanced Persistent Threat 高级可持续威胁攻击。指的是某组织对特定对象展开持续有效的攻击活动。这种攻击活动具有极强的隐蔽性和针对性&#xff0c;通常会运用受感染的各种介质&#xff0c;供应链和社会工程学等手段&#xff0c;实施先…

【Vue全家桶】细说slot

【Vue全家桶】细说slot 文章目录【Vue全家桶】细说slot前言一、认识插槽Slot1.1 插槽的基本使用二、插槽的使用2.1 默认内容2.2 剧名插槽2.3 作用域插槽前言 我们已经了解到组件能够接收任意类型的 JavaScript 值作为 props&#xff0c;但组件要如何接收模板内容呢&#xff1f;…

【翻译】使用Go生成一个随机字符串(密码)

来源&#xff1a; Generate a random string (password) YourBasic Go https://yourbasic.org/golang/generate-random-string/ Random string 随机字符串 This code generates a random string of numbers and characters from the Swedish alphabet (which includes the non…
最新文章