您好,登錄后才能下訂單哦!
這篇文章主要介紹了vue3+ts怎么使用APlayer的相關知識,內容詳細易懂,操作簡單快捷,具有一定借鑒價值,相信大家閱讀完這篇vue3+ts怎么使用APlayer文章都會有所收獲,下面我們一起來看看吧。
yarn add aplayer
<!-- <!-- * @Author: MK * @Date: 2021-12-16 15:41:47 * @LastEditTime: 2021-12-24 11:17:45 * @LastEditors: MK * @Description: APlayer組件化 * @FilePath: \vue-mk-blog\src\components\APlayer.vue --> <template> <div ref="playerRef"></div> </template> <script lang="ts" setup> import http from '@/api/http' import APlayer from 'APlayer'; import 'APlayer/dist/APlayer.min.css'; import type {PropType} from '@vue/runtime-core'; import {nextTick, onBeforeUnmount, onMounted, ref} from 'vue' const playerRef = ref() let instance: APlayer; // APlayer歌曲信息 class Audio { // 音頻藝術家 artist: String; // 音頻名稱 name: String; // 音頻鏈接 url: String; // 音頻封面 cover: String; // 歌詞 lrc: String; constructor(artist: String, name: String, url: String, cover: String, lrc: String) { this.artist = artist; this.name = name; this.url = url; this.cover = cover; this.lrc = lrc; } } const props = defineProps({ // 開啟吸底模式 fixed: { type: Boolean as PropType<boolean>, default: true }, // 開啟迷你模式 mini: { type: Boolean as PropType<boolean>, default: true }, // 音頻自動播放 autoplay: { type: Boolean as PropType<boolean>, default: false }, // 主題色 theme: { type: String as PropType<string>, default: 'rgba(255,255,255,0.2)' }, // 音頻循環播放 loop: { type: String as PropType<'all' | 'one' | 'none'>, default: 'all' }, // 音頻循環順序 order: { type: String as PropType<'list' | 'random'>, default: 'random' }, // 預加載 preload: { type: String as PropType<'auto' | 'metadata' | 'none'>, default: 'auto' }, // 默認音量 volume: { type: Number as PropType<number>, default: 0.7, validator: (value: Number) => { return value >= 0 && value <= 1; } }, // 歌曲服務器(netease-網易云, tencent-qq音樂, kugou-酷狗, xiami-小米音樂, baidu-百度音樂) songServer: { type: String as PropType<'netease' | 'tencent' | 'kugou' | 'xiami' | 'baidu'>, default: 'netease' }, // 播放類型(song-歌曲, playlist-播放列表, album-專輯, search-搜索, artist-藝術家) songType: { type: String as PropType<string>, default: 'playlist' }, // 歌的id songId: { type: String as PropType<string>, default: '19723756' }, // 互斥,阻止多個播放器同時播放,當前播放器播放時暫停其他播放器 mutex: { type: Boolean as PropType<boolean>, default: true }, // 傳遞歌詞方式 lrcType: { type: Number as PropType<number>, default: 3 }, // 列表是否默認折疊 listFolded: { type: Boolean as PropType<boolean>, default: true }, // 列表最大高度 listMaxHeight: { type: String as PropType<string>, default: '100px' }, // 存儲播放器設置的 localStorage key storageName: { type: String as PropType<string>, default: 'aplayer-setting' } }) // 初始化 onMounted(() => { nextTick(() => { http.player.getSongSheet(props.songServer, props.songType, props.songId) .then(res => { let audioList = res.data.map(value => new Audio(value.author, value.title, value.url, value.pic, value.lrc)); instance = new APlayer({ container: playerRef.value, fixed: props.fixed, mini: props.mini, autoplay: props.autoplay, theme: props.theme, loop: props.loop, order: props.order, preload: props.preload, volume: props.volume, mutex: props.mutex, lrcType: props.lrcType, listFolded: props.listFolded, listMaxHeight: props.listMaxHeight, storageName: props.storageName, audio: audioList }) }) }) }) // 銷毀 onBeforeUnmount(() => { instance.destroy() }) </script>
import axios from '@/utils/axios' export class player { static getSongSheet(server: string, type:String, id: String) { return axios.get(`https://api.i-meto.com/meting/api?server=${server}&type=${type}&id=${id}&r=${Math.random()}`); } }
關于“vue3+ts怎么使用APlayer”這篇文章的內容就介紹到這里,感謝各位的閱讀!相信大家對“vue3+ts怎么使用APlayer”知識都有一定的了解,大家如果還想學習更多知識,歡迎關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。