mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-04-29 11:27:23 +08:00
添加音量控制条
This commit is contained in:
@@ -60,8 +60,6 @@ const playMusic = computed(() => store.state.playMusic);
|
|||||||
|
|
||||||
// 判断是否为正在播放的音乐
|
// 判断是否为正在播放的音乐
|
||||||
const isPlaying = computed(() => {
|
const isPlaying = computed(() => {
|
||||||
console.log(1231223, playMusic.value.id, props.item.id);
|
|
||||||
|
|
||||||
return playMusic.value.id == props.item.id;
|
return playMusic.value.id == props.item.id;
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -27,22 +27,24 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="music-time">
|
<div class="music-time">
|
||||||
<div class="time">{{ getNowTime }}</div>
|
<div class="time">{{ getNowTime }}</div>
|
||||||
<n-slider v-model:value="timeSlider" :step="0.05">
|
<n-slider v-model:value="timeSlider" :step="0.05" :tooltip="false"></n-slider>
|
||||||
<template #tooltip>
|
|
||||||
<div>1231</div>
|
|
||||||
</template>
|
|
||||||
</n-slider>
|
|
||||||
<div class="time">{{ getAllTime }}</div>
|
<div class="time">{{ getAllTime }}</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="audio-volume">
|
||||||
|
<div>
|
||||||
|
<i class="iconfont icon-notificationfill"></i>
|
||||||
|
</div>
|
||||||
|
<n-slider v-model:value="volumeSlider" :step="0.01" :tooltip="false"></n-slider>
|
||||||
|
</div>
|
||||||
<!-- 播放音乐 -->
|
<!-- 播放音乐 -->
|
||||||
<audio ref="audio" :src="playMusicUrl" :autoplay="play"></audio>
|
<audio ref="audio" :src="playMusicUrl" :autoplay="play"></audio>
|
||||||
<n-button @click="playMusicEvent">playMusicEvent</n-button>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { SongResult } from "@/type/music";
|
import type { SongResult } from "@/type/music";
|
||||||
import { secondToMinute } from "@/utils";
|
import { secondToMinute } from "@/utils";
|
||||||
|
import { c } from "naive-ui";
|
||||||
import { computed, onBeforeUpdate, onMounted, ref, watch } from "vue";
|
import { computed, onBeforeUpdate, onMounted, ref, watch } from "vue";
|
||||||
import { useStore } from 'vuex';
|
import { useStore } from 'vuex';
|
||||||
|
|
||||||
@@ -95,6 +97,15 @@ const timeSlider = computed({
|
|||||||
audio.value.currentTime = value * allTime.value / 100
|
audio.value.currentTime = value * allTime.value / 100
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 音量条
|
||||||
|
const audioVolume = ref(1)
|
||||||
|
const volumeSlider = computed({
|
||||||
|
get: () => audioVolume.value * 100,
|
||||||
|
set: (value) => {
|
||||||
|
audio.value.volume = value / 100
|
||||||
|
}
|
||||||
|
})
|
||||||
// 获取当前播放时间
|
// 获取当前播放时间
|
||||||
const getNowTime = computed(() => {
|
const getNowTime = computed(() => {
|
||||||
return secondToMinute(nowTime.value)
|
return secondToMinute(nowTime.value)
|
||||||
@@ -108,9 +119,13 @@ const getAllTime = computed(() => {
|
|||||||
// 监听音乐播放 获取时间
|
// 监听音乐播放 获取时间
|
||||||
const onAudio = (audio: any) => {
|
const onAudio = (audio: any) => {
|
||||||
audio.addEventListener("timeupdate", function () {//监听音频播放的实时时间事件
|
audio.addEventListener("timeupdate", function () {//监听音频播放的实时时间事件
|
||||||
//用秒数来显示当前播放进度
|
// 获取当前播放时间
|
||||||
nowTime.value = audio.currentTime
|
nowTime.value = audio.currentTime
|
||||||
|
// 获取总时间
|
||||||
allTime.value = audio.duration
|
allTime.value = audio.duration
|
||||||
|
// 获取音量
|
||||||
|
audioVolume.value = audio.volume
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,9 +185,17 @@ const playMusicEvent = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.music-time {
|
.music-time {
|
||||||
@apply flex flex-1;
|
@apply flex flex-1 items-center;
|
||||||
.time {
|
.time {
|
||||||
@apply mx-4;
|
@apply mx-4 mt-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.audio-volume {
|
||||||
|
width: 180px;
|
||||||
|
@apply flex items-center mx-4;
|
||||||
|
.iconfont {
|
||||||
|
@apply text-2xl hover:text-green-500 transition cursor-pointer mr-4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
Reference in New Issue
Block a user