音乐播放器

  • 前言
  • 主页
  • 三个标签页
    • 推荐页
    • 播放器页
    • 播放列表页
  • 逻辑

前言

使用swiper组件完成三个标签页的切换,并且实现轮播图。scroll-view组件完成滚动视图,使用微信小程序提供的音乐API播放音频。

主页

主页
index.wxml

<view class="nav"><view class="nav-item {{currentTab==0?'active':''}}" bindtap="switchTab" data-tab="0">音乐推荐</view><view class="nav-item {{currentTab==1?'active':''}}" bindtap="switchTab" data-tab="1">播放器</view><view class="nav-item {{currentTab==2?'active':''}}" bindtap="switchTab" data-tab="2">播放列表</view>
</view><!-- 标签页 -->
<view class="main">
<swiper current="{{currentTab}}" bindchange="changeTab"><swiper-item class="nav-item"><include src="recommend.wxml" /></swiper-item><swiper-item class="nav-item"><include src="play.wxml" /></swiper-item><swiper-item class="nav-item"><include src="playlist.wxml" /></swiper-item></swiper>
</view><!-- 底部播放器 -->
<view class="playing"><view class="thumb"><image src="{{play.coverImgUrl}}"></image></view><view class="info"><view class="title">{{play.title}}</view><view class="authors">{{play.singer}}</view></view><view class="controls"><image src="/images/01.png" bindtap="changePage" data-page="2" /><image wx:if="{{state=='paused'}}" src="/images/02.png" bindtap="play" /><image wx:else src="/images/02stop.png" bindtap="pause" /><image src="/images/03.png" bindtap="next" /></view>
</view>

index.wxss


@import "recommend.wxss";
@import "play.wxss";
@import "playlist.wxss";
page{background-color: #17181a;color: #ccc;font-size: 35rpx;display: flex;flex-direction: column;height: 100%;
}
/* 导航栏 */
.nav{height: 80rpx;line-height: 80rpx;display: flex;
}.nav-item{flex: 1;flex-basis:33.3%;text-align: center;
}
.active{color: orange;
}
/* 主体 */
.main{flex: 1;height: 100%;
}
.main>swiper{height: 100%;
}/* 底部 */
.playing{height: 120rpx;display: flex;
}
.thumb{width: 120rpx;}
.thumb>image{width: 110rpx;height: 110rpx;margin: 5rpx;
}
.info{flex: 1;
}
.info>view{height: 60rpx;line-height: 60rpx;
}
.controls{width: 250rpx;
}
.controls>image{width: 80rpx;height: 80rpx;margin-top: 20rpx;
}

三个标签页

推荐页

recommend.wxml

<!-- 内容滚动区域 -->
<scroll-view class="content-info" scroll-y><!-- 轮播图 --><swiper class="content-info-slide" indicator-color="rgba(255,255,255,.5)" indicator-active-color="#fff" indicator-dots circular autoplay><swiper-item><image src="/images/1.jpg" /></swiper-item><swiper-item><image src="/images/2.jpg" /></swiper-item><swiper-item><image src="/images/4.jpg" /></swiper-item></swiper><!-- 功能按钮 --><view class="content-info-portal"><view><image src="/images/04.png" /><text>私人FM</text></view><view><image src="/images/05.png" /><text>每日歌曲推荐</text></view><view><image src="/images/06.png" /><text>云音乐新歌榜</text></view></view><!-- 热门音乐 --><view class="content-info-list"><view class="list-title">推荐歌曲</view><view class="list-inner"><view class="list-item"><image src="/images/cover.jpg" /><view>紫罗兰</view></view><view class="list-item"><image src="/images/cover.jpg" /><view>五月之歌</view></view><view class="list-item"><image src="/images/cover.jpg" /><view>菩提树</view></view><view class="list-item"><image src="/images/cover.jpg" /><view>欢乐颂</view></view><view class="list-item"><image src="/images/cover.jpg" /><view>安魂曲</view></view><view class="list-item"><image src="/images/cover.jpg" /><view>摇篮曲</view></view></view></view>
</scroll-view>

index.wxss


.content-info {height: 100%;
}::-webkit-scrollbar {width: 0;height: 0;color: transparent;
}/* 轮播图 */.content-info-slide {height: 302rpx;margin-bottom: 20px;
}.content-info-slide image {width: 100%;height: 100%;
}/* 功能按钮 */.content-info-portal {display: flex;margin-bottom: 15px;
}.content-info-portal > view {flex: 1;font-size: 11pt;text-align: center;
}.content-info-portal image {width: 120rpx;height: 120rpx;display: block;margin: 20rpx auto;
}/* 热门音乐 */.content-info-list {font-size: 11pt;margin-bottom: 20rpx;
}.content-info-list > .list-title {margin: 20rpx 35rpx;
}.content-info-list > .list-inner {display: flex;flex-wrap: wrap;margin: 0 20rpx;
}.content-info-list > .list-inner > .list-item {flex: 1;
}.content-info-list > .list-inner > .list-item > image {display: block;width: 200rpx;height: 200rpx;margin: 0 auto;border-radius: 10rpx;border: 1rpx solid #555;
}.content-info-list > .list-inner > .list-item > view {width: 200rpx;margin: 10rpx auto;font-size: 10pt;
}

播放器页

play.wxml

<view class="play"><!-- 基本信息 --><view class="music_info"><view class="name">{{play.title}}</view><view class="auto">{{play.singer}}</view></view><!-- 封面 --><view class="cover"><image src="{{play.coverImgUrl}}" style="animation-play-state:{{state}}" /></view><!-- 进度条 --><view class="progress"><!-- 显示播放进度和时间 --><text>{{play.currentTime}}</text><slider bindchange="sliderChange" activeColor="#d33a31" block-size="12" backgroundColor="#dadada"value="{{play.percent}}" /><text>{{play.duration}}</text></view></view>

play.wxss

.play {display: flex;flex-direction: column;
}/*  */
.music_info {text-align: center;margin-top: 20rpx;margin-bottom: 20rpx;
}/*  */
.cover {margin-top: 80rpx;margin-bottom: 120rpx;flex: 1;
}.cover>image {width: 400rpx;height: 400rpx;display: block;margin: 0 auto;border-radius: 50%;/* 动画旋转 */animation: rotateImage 10s linear infinite;
}@keyframes rotateImage {from {transform: rotate(0deg);}to {transform: rotate(360deg);}
}.progress{padding-bottom: 50rpx;display: flex;
}
.progress>slider{display: inline-block;/* width: 400rpx; */flex: 1;
}
.progress>text{padding: 16rpx;height: 50rpx;line-height: 50rpx;
}

播放列表页

playist.wsml

<scroll-view class="playlist" scroll-y><view class="playlist-item" wx:for="{{musics}}" wx:key="id" bindtap="change" data-index="{{index}}"><image class="playlist-cover" src="{{item.coverImgUrl}}" /><view class="playlist-info"><view class="playlist-info-title">{{item.title}}</view><view class="playlist-info-singer">{{item.singer}}</view></view><view class="playlist-controls"><text wx:if="{{index==playIndex}}">正在播放</text></view></view>
</scroll-view>

playist.wsss

.playlist-item {display: flex;align-items: left;border-bottom: 1rpx solid #333;height: 140rpx;
}.playlist-cover {width: 100rpx;height: 100rpx;margin: 12rpx;margin-left: 20rpx;border-radius: 8rpx;border: 1px solid #333;
}.playlist-info {flex: 1;font-size: 12pt;line-height: 50rpx;margin-left: 10rpx;text-align: left;padding-bottom: 8rpx;margin-top: 12rpx;
}.playlist-info-singer {color: #888;
}.playlist-controls {font-size: 12pt;margin-right: 30rpx;color: #c25b5b;
}

逻辑

index.js

Page({/*** 页面的初始数据*/data: {currrentTab: 1,musics: [{id: 1,title: '智联世界',singer: '小冰',src: '/audio/智联家园.mp3',coverImgUrl: '/images/小冰.jpg'}, {id: 2,title: '不要认输',singer: '坂井泉水',src: '/audio/不要认输.mp3',coverImgUrl: '/images/坂井泉水.jpg'}, {id: 3,title: '白桦林',singer: '朴树',src: '/audio/白桦林.mp3',coverImgUrl: '/images/朴树.jpg'}, {id: 4,title: '红豆',singer: '王菲',src: '/audio/红豆.mp3',coverImgUrl: '/images/王菲.jpg'}],state: 'paused',playIndex: 0,play: {currentTime: '00:00',duration: '00:00',percent: 0,title: '',singer: '',coverImgUrl: '/images/cover.jpg',}},// 单击导航栏拿到自定义属性switchTab: function (e) {// var tab = e.target.dataset.tab// this.setData({//   currrentTab:tab// })this.setData({currentTab: e.target.dataset.tab,})},changeTab: function (e) {// var tab = e.target.dataset.tab// this.setData({//   currrentTab:tab// })this.setData({currentTab: e.detail.current})},// 实现播放器播放功能audioCtx: null,onReady: function() {this.audioCtx = wx.createInnerAudioContext()// 默认选择第1曲this.setMusic(0)var that = this// 播放进度检测this.audioCtx.onError(function() {console.log('播放失败:' + that.audioCtx.src)})// 播放完成自动换下一曲this.audioCtx.onEnded(function() {that.next()})// 自动更新播放进度this.audioCtx.onPlay(function() {})this.audioCtx.onTimeUpdate(function() {that.setData({'play.duration': formatTime(that.audioCtx.duration),'play.currentTime': formatTime(that.audioCtx.currentTime),'play.percent': that.audioCtx.currentTime / that.audioCtx.duration * 100})})// 格式化时间function formatTime(time) {var minute = Math.floor(time / 60) % 60;var second = Math.floor(time) % 60return (minute < 10 ? '0' + minute : minute) + ':' + (second < 10 ? '0' + second : second)}},// 音乐播放setMusic: function(index) {var music = this.data.musics[index]this.audioCtx.src = music.srcthis.setData({playIndex: index,'play.title': music.title,'play.singer': music.singer,'play.coverImgUrl': music.coverImgUrl,'play.currentTime': '00:00','play.duration': '00:00','play.percent': 0})},// 播放按钮play: function() {this.audioCtx.play()this.setData({state: 'running'})},// 暂停按钮pause: function() {this.audioCtx.pause()this.setData({state: 'paused'})},// 下一曲按钮next: function() {var index = this.data.playIndex >= this.data.musics.length - 1 ? 0 : this.data.playIndex + 1this.setMusic(index)if (this.data.state === 'running') {this.play()}},// 滚动条调节歌曲进度sliderChange: function(e) {var second = e.detail.value * this.audioCtx.duration / 100this.audioCtx.seek(second)},// 播放列表换曲功能change: function(e) {this.setMusic(e.currentTarget.dataset.index)this.play()}

微信小程序——音乐播放器相关推荐

  1. 微信小程序音乐播放器

    趁周末做一个简单的微信小程序音乐播放器,源码已留. 播放列表首页wxml <swiper class="swiper" indicator-dots='{{swipterSe ...

  2. (附源码)springboot+基于微信小程序音乐播放器的设计与实现 毕业设计271156

    Springboot音乐播放小程序的设计与实现 摘 要 本文设计了一种基于微信小程序的音乐播放器,系统为人们提供了方便快捷.即用即搜的音乐搜索播放服务,包括音乐资讯.音乐库推荐.交流论坛.注册登录.最 ...

  3. springboot+基于微信小程序音乐播放器的设计与实现 毕业设计-附源码271156

    Springboot音乐播放小程序的设计与实现 摘 要 本文设计了一种基于微信小程序的音乐播放器,系统为人们提供了方便快捷.即用即搜的音乐搜索播放服务,包括音乐资讯.音乐库推荐.交流论坛.注册登录.最 ...

  4. 基于微信小程序音乐播放器

    随着我国经济迅速发展,人们对手机的需求越来越大,各种手机软件也都在被广泛应用,但是对于手机进行数据信息管理,对于手机的各种软件也是备受用户的喜爱,音乐播放器小程序被用户普遍使用,为方便用户能够可以随时 ...

  5. 微信小程序-音乐播放器

    前言 本文主要通过微信小程序的媒体API来实现一个简单的音乐播放器,主要实现的功能有音乐的切换.单曲循环.播放进度条的拖拽.播放与暂停和自定义音乐列表弹窗功能. 效果图 主要目录文件 |--image ...

  6. 01. 微信小程序音乐播放器

    项目简介 最近在学微信小程序,所以打算做一个音乐播放器的微信小程序. 项目需求(原型图) 这个是我做的原型图,比较简陋(有些界面直接用了网易云音乐小程序的截图,因为是仿着网易云音乐来做的) 首页 播放 ...

  7. java基于微信小程序音乐播放器分享系统 uniapp 小程序

    音乐播放器小程序的设计主要是对系统所要实现的功能进行详细考虑,确定所要实现的功能后进行界面的设计,在这中间还要考虑如何可以更好的将功能及页面进行很好的结合,方便用户可以很容易明了的找到自己所需要的信息 ...

  8. 计算机实战项目、毕业设计、课程设计之含论文+辩论PPT+源码等]微信小程序音乐播放器小程序+后台管理系统

    音乐播放器平台+后台管理系统|前后分离VUE>该项目含有源码.论文等资料.配套开发软件.软件安装教程.项目发布教程等 本系统包含微信小程序前台和Java做的后台管理系统,该后台采用前后台前后分离 ...

  9. java微信小程序音乐播放器分享系统

    随着我国经济迅速发展,人们对手机的需求越来越大,各种手机软件也都在被广泛应用,但是对于手机进行数据信息管理,对于手机的各种软件也是备受用户的喜爱,音乐播放器小程序被用户普遍使用,为方便用户能够可以随时 ...

最新文章

  1. 西部数码虚拟主机服务器配置,西部数码虚拟主机设置首页功能介绍
  2. 计算机病毒洛,蓝狐动漫《百变机兽》中未完的战争,蓝毒兽原来是电脑病毒?...
  3. 查看linux内存存储空间不足,Linux 下判断Server 内存是否不足
  4. Redis命令:SETNX key value(SET if Not eXists)
  5. vue实例没有挂载到html上,VueJS-将数据发送到Vue实例以用于挂载()
  6. query什么意思php,关于 QueryPHP
  7. openai-gpt_您可以使用OpenAI GPT-3语言模型做什么?
  8. 【渝粤教育】 国家开放大学2020年春季 2064管理学基础 参考试题
  9. flash绘制荷花多个图层_Flash鼠绘入门第八课:绘制脱俗荷花
  10. Linux实战 | Centos6.8安装matlab的mount挂载问题的解决方法_3
  11. 专栏:谈谈我对当下大数据整顿的理解与风控建议
  12. 免费查题合集大推荐,付费根本不存在的!
  13. 深度数据对接 链接服务器 数据传输
  14. 使用java的io流编写日志类
  15. win10计算机优化技巧,教你win10优化技巧
  16. 强化学习总结(1)--EE问题
  17. 2022短视频去水印小程序源码+支持批量解析
  18. 【写paper系列之一】怎样写好introduction--转自nature
  19. Python-----从所示的三门成绩中,生成个人成绩单,并显示每个人选修了几门课程。
  20. Excel-汉字中提取数字

热门文章

  1. 自己初步了解python数据爬虫
  2. 《程序员的思维修炼--开发认知潜能》读书笔记
  3. Android无法播放本地视频
  4. ffmpeg 分辨率 压缩_视频怎么在尽量不损害画质的前提下压缩?
  5. OpenCV VideoCapture 设置和获取摄像头参数
  6. 云服务器租赁维护合同,云服务器 租赁 服务合同
  7. 利用PyCharm实现服务器远程代码开发
  8. 【图】高考前最后一篇博客(如果你是常客,就点开看看吧!)
  9. 南京湖南路学计算机哪家好,南京“最好吃餐厅排行榜”,去过8个,你就是超级美食达人......
  10. 宝宝的肚子看起来是鼓鼓胀胀