更新记录
1.0.1(2025-06-09)
下载此版本
兼容微信小程序
1.0.0(2025-06-08)
下载此版本
初始化
平台兼容性
uni-app
Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
√ |
√ |
√ |
√ |
√ |
- |
- |
- |
- |
微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
√ |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
其他
nl-audio-player
音乐播放器
基本使用
<template>
<view class="wrap">
<view style="margin: 60rpx; color: #999">实现各种效果</view>
<!-- 保留播放条,自行调用方法来播放,暂停,切歌(修改播放地址) -->
<view style="margin: 60rpx">
<nl-audio-player :src="audioUrl" height="2" size="16" :playerStyle="{}" :show-play-btn="false"></nl-audio-player>
<view class="audio-control-wrapper">
<view class="audio-control audio-control-prev"></view>
<view class="audio-control audio-control-switch"></view>
<view class="audio-control audio-control-next"></view>
</view>
</view>
<view style="margin: 60rpx; color: #999">配置效果</view>
<view style="margin: 60rpx 60rpx">
<nl-audio-player :src="audioUrl" height="2" size="16" :playerStyle="{}" :show-play-btn="false" :show-date="false"></nl-audio-player>
</view>
<nl-audio-player :src="audioUrl" date-mode="bottom"></nl-audio-player>
<nl-audio-player
:src="audioUrl"
height="10"
:bar-bg-style="{ borderRadius: '50px' }"
:bar-style="{ backgroundColor: 'blue', borderRadius: '50px' }"
:dot-style="{ width: '30rpx', height: '30rpx', backgroundColor: 'red' }"
></nl-audio-player>
<nl-audio-player :src="audioUrl" date-mode="top" :show-play-btn="false"></nl-audio-player>
<nl-audio-player ref="audioRef" :src="audioUrl" :duration="16" loop date-mode="side" :play-btn-style="{ backgroundColor: '#409eff' }" :date-style="{ color: '#409eff' }"></nl-audio-player>
<view style="display: flex">
<button type="default" @click="handlePlay">播放</button>
<button type="default" @click="handlePause">暂停</button>
<button type="default" @click="handleAdd">增加音量</button>
<button type="default" @click="handleReduce">减少音量</button>
</view>
<view style="display: flex; margin-top: 10px">
<button type="default" @click="handlePlaybackBate(0.5)">0.5倍数</button>
<button type="default" @click="handlePlaybackBate(1)">正常</button>
<button type="default" @click="handlePlaybackBate(2)">2倍数</button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
audioUrl: 'https://audio.lzkp/clock.mp3', // 使用自己的音频地址
volume: 1,
}
},
methods: {
handlePlay() {
this.$refs.audioRef.play()
},
handlePause() {
this.$refs.audioRef.pause()
},
handleAdd() {
this.volume = Number((this.volume + 0.1).toFixed(1))
this.$refs.audioRef.setVolume(this.volume)
},
handleReduce() {
this.volume = Number((this.volume - 0.1).toFixed(1))
this.$refs.audioRef.setVolume(this.volume)
},
handlePlaybackBate(val) {
this.$refs.audioRef.setPlaybackRate(val)
},
},
}
</script>
<style>
@font-face {
font-family: 'icon';
src: url('//at.alicdn.com/t/c/font_4943412_hwr994uqfdf.woff2?t=1749392833400') format('woff2'), url('//at.alicdn.com/t/c/font_4943412_hwr994uqfdf.woff?t=1749392833400') format('woff'),
url('//at.alicdn.com/t/c/font_4943412_hwr994uqfdf.ttf?t=1749392833400') format('truetype');
}
.audio-control-wrapper {
margin-top: 20rpx;
display: flex;
justify-content: center;
align-items: center;
font-family: 'icon' !important;
}
.audio-control {
font-size: 62rpx;
line-height: 1;
padding: 16rpx;
color: #409eff;
font-size: 80rpx;
}
.audio-control-prev {
transform: rotate(180deg);
}
.audio-control-switch {
font-size: 80rpx;
margin: 0 100rpx;
}
</style>
Props
属性 |
说明 |
类型 |
默认值 |
src |
音频地址(必填) |
String |
|
duration |
音频总时长,在未读取到音频时长时显示该值,读取成功后替换为真实时长(微信小程序在未播放音频时获取不到真实时长,微信bug) |
String |
|
height |
播放条高度 |
String/Number |
6 (单位px) |
size |
播放条圆点 |
String/Number |
16 (单位px) |
volume |
音量。范围 [0,1] |
Number |
1 |
loop |
是否循环播放 |
Boolean |
false |
autoplay |
是否自动开始播放 |
String |
false |
playbackRate |
播放的倍率 ,可取值:0.5/0.8/1.0/1.25/1.5/2.0,App 3.4.5+(Android 需要 6 及以上版本)、微信小程序 2.11.0、支付宝小程序、抖音小程序 2.33.0+、快手小程序、百度小程序 3.120.2+ |
Boolean |
1 |
showDate |
是否显示播放时间 |
Boolean |
true |
dateMode |
播放时间显示的方式:两侧('side'),上方('top'),下方('bottom') |
String |
'side' |
showPlayBtn |
是否播放按钮 |
Boolean |
true |
playBtnStyle |
播放按钮样式 |
Object |
|
barStyle |
自定义播放条样式 |
Object |
|
barBgStyle |
自定义播放条背景样式 |
Object |
|
dotStyle |
自定义播放条圆点样式 |
Object |
|
dateStyle |
显示的音频时间样式 |
Object |
|
playerStyle |
自定义播放器样式,可以设置为{} ,这样可以只保留播放条,自己布局 |
Object |
{padding: '30rpx',backgroundColor: '#fff',borderRadius: '16rpx',boxShadow: '0 4rpx 20rpx rgba(0, 0, 0, 0.1)',margin: '26rpx'} |
Methods
属性 |
说明 |
参数 |
play |
播放 |
|
height |
暂停 |
|
setVolume |
设置音量,范围 [0,1] |
Function(val) |
setPlaybackRate |
设置播放倍率,可取值:0.5/0.8/1.0/1.25/1.5/2.0 |
Function(val) |
getAudioContext |
获取音频上下文 |
|