当前位置: 首页 > news >正文

网站建设的招标文件/国内seo公司

网站建设的招标文件,国内seo公司,wordpress app for ios 3.4下载,电商网站运营团队建设方案微信小程序实现一个音乐播放器的功能 要求代码实现wxml 文件wxss 文件js文件 解析 要求 1.页面包含一个音乐列表,点击列表中的音乐可以播放对应的音乐。 2.播放中的音乐在列表中有标识,并且可以暂停或继续播放。 3.显示当前音乐的播放进度和总时长&#…

微信小程序实现一个音乐播放器的功能

    • 要求
    • 代码实现
      • wxml 文件
      • wxss 文件
      • js文件
    • 解析

要求

1.页面包含一个音乐列表,点击列表中的音乐可以播放对应的音乐。
2.播放中的音乐在列表中有标识,并且可以暂停或继续播放。
3.显示当前音乐的播放进度和总时长,并可以拖动进度条调整播放进度。
4.点击切换按钮可以切换到下一首音乐。
5.点击循环按钮可以切换音乐的播放模式(单曲循环、列表循环、随机播放)。

代码实现

wxml 文件

<view class="container"><scroll-view scroll-y class="music-list"><view wx:for="{{ musicList }}" wx:key="{{ index }}" class="music-item" bindtap="onMusicTap" data-index="{{ index }}"><view class="music-name">{{ item.name }}</view><view class="music-artist">{{ item.artist }}</view></view></scroll-view><audio id="audio" src="{{ currentMusic.src }}" bindtimeupdate="onTimeUpdate" bindended="onEnded"></audio><view class="player"><view class="controls"><button class="control-btn" bindtap="onPrev">上一首</button><button class="control-btn" bindtap="onPlayOrPause">{{ playing ? '暂停' : '播放' }}</button><button class="control-btn" bindtap="onNext">下一首</button><button class="control-btn" bindtap="onChangeMode">模式</button></view><view class="progress"><text>{{ currentTime }}</text><slider max="{{ duration }}" value="{{ currentPosition }}" bindchange="onSliderChange" /><text>{{ durationStr }}</text></view></view>
</view>

wxss 文件

.container {padding: 20rpx;
}.music-list {height: 300rpx;
}.music-item {padding: 10rpx;border-bottom: 1rpx solid #eee;text-align: left;
}.player {margin-top: 20rpx;display: flex;flex-direction: column;align-items: center;
}.controls {display: flex;justify-content: space-around;width: 100%;margin-bottom: 10rpx;
}.control-btn {background-color: #009688;color: #fff;padding: 10rpx 20rpx;border-radius: 4rpx;
}progress {display: flex;align-items: center;
}.slider {flex: 1;margin: 0 10rpx;
}

js文件

Page({data: {musicList: [{ name: '歌曲1', artist: '歌手1', src: 'music1.mp3' },{ name: '歌曲2', artist: '歌手2', src: 'music2.mp3' },// 更多音乐...],currentMusic: {},playing: false,duration: 0,currentPosition: 0,currentTime: '00:00',durationStr: '00:00',playMode: 0, // 0: 列表循环,1: 单曲循环,2: 随机播放},onMusicTap(e) {const index = e.currentTarget.dataset.index;const music = this.data.musicList[index];this.setData({currentMusic: music,playing: true,});this.playMusic();},onPlayOrPause() {if (this.data.playing) {this.pauseMusic();} else {this.playMusic();}},playMusic() {const audio = this.selectComponent('#audio');audio.play();this.setData({playing: true,});},pauseMusic() {const audio = this.selectComponent('#audio');audio.pause();this.setData({playing: false,});},onPrev() {let currentIndex = this.data.musicList.findIndex(item => item.src === this.data.currentMusic.src);if (currentIndex === 0) {currentIndex = this.data.musicList.length - 1;} else {currentIndex--;}const music = this.data.musicList[currentIndex];this.setData({currentMusic: music,playing: true,});this.playMusic();},onNext() {let currentIndex = this.data.musicList.findIndex(item => item.src === this.data.currentMusic.src);if (currentIndex === this.data.musicList.length - 1) {currentIndex = 0;} else {currentIndex++;}const music = this.data.musicList[currentIndex];this.setData({currentMusic: music,playing: true,});this.playMusic();},onTimeUpdate(e) {const duration = e.detail.duration;const currentPosition = e.detail.currentTime;const currentTime = this.formatTime(currentPosition);const durationStr = this.formatTime(duration);this.setData({duration: duration,currentPosition: currentPosition,currentTime: currentTime,durationStr: durationStr,});},onEnded() {if (this.data.playMode === 1) {// 单曲循环const audio = this.selectComponent('#audio');audio.seek(0);audio.play();} else {this.onNext();}},onSliderChange(e) {const value = e.detail.value;const audio = this.selectComponent('#audio');audio.seek(value);},onChangeMode() {let playMode = this.data.playMode;playMode = (playMode + 1) % 3;this.setData({playMode: playMode,});},formatTime(time) {const minutes = Math.floor(time / 60);const seconds = Math.floor(time % 60);const minuteStr = minutes < 10 ? '0' + minutes : '' + minutes;const secondStr = seconds < 10 ? '0' + seconds : '' + seconds;return minuteStr + ':' + secondStr;},
});

解析

其中,onPrev() 和 onNext() 函数实现了切换到上一首和下一首音乐的逻辑。通过 findIndex()
函数找到当前音乐在列表中的位置,然后根据播放模式计算出下一首或上一首音乐的位置,更新当前音乐并播放。

onTimeUpdate() 函数实现了更新播放进度的逻辑,通过 detail 参数获取音频的总时长和当前播放进度,并格式化成 00:00
的形式,更新页面数据。

onEnded() 函数实现了音乐播放结束的逻辑,根据当前的播放模式决定是单曲循环还是切换到下一首音乐。

onSliderChange() 函数实现了调整播放进度的逻辑,通过 seek() 函数跳转到指定的时间点。

onChangeMode() 函数实现了切换播放模式的逻辑,通过取余操作循环切换三种播放模式。

到这里也就结束了,希望对您有所帮助。

http://www.ho-use.cn/article/465.html

相关文章:

  • 长沙微商城网站建设/上海网站排名seo公司哪家好
  • 天水建设网站/付费推广平台有哪些
  • 南昌网站搭建制作公司/不受限制的浏览器
  • 学做美食交流网站有哪些/网址查询工具
  • 做赛事预测网站/百度云登录首页
  • 支付招聘网站套餐费用怎么做帐/百度关键词排名点
  • 怎么注册公司邮箱账号/seo网站关键词优化
  • 做网站程序的都不关注seo/百度推广怎么登录
  • 英文网站建设比较好/网络服务合同纠纷
  • 建设景区网站推文/网络营销的特点举例说明
  • 网站建设网站需要什么软件/人民日报最新新闻
  • 下载类网站做多久才有流量/百度app免费下载安装
  • 房产网站开发/百度上广告怎么搞上去的
  • 驻马店网站开发公司/浙江网站seo
  • 菏泽市城乡建设局网站有什么功能
  • 武汉做家电的团购网站/信息发布
  • 外网图片素材网站/希爱力双效片副作用
  • 漳州北京网站建设公司哪家好/怎样在网上做推广
  • wordpress博客实例/网站seo设置是什么
  • 免费看黄金的软件/网站seo分析报告
  • 巩义做网站xd seo/企业网站运营推广
  • 深圳做网站哪里最好/搜狗官网
  • 自适应产品网站模板/百度首页纯净版
  • 企业网站建设ppt模板/百度竞价排名查询
  • 做网站制作一般多少钱/快速seo整站优化排行
  • 企业网站推广哪些效果比较好/360推广登陆入口
  • 网站建设服务哪家好/二级不死域名购买
  • 我想做京东网站淘宝怎么做/创建一个网站需要什么
  • 用什么软件做公司网站/新疆疫情最新情况
  • 衢州站扩建/seo推广怎么收费