精简部分播放器代码

This commit is contained in:
灌糖包子 2023-01-28 01:02:19 +08:00
parent 289d7e0b8b
commit 2be35021b4
Signed by: sookie
GPG Key ID: 691E688C160D3188
7 changed files with 26 additions and 54 deletions

View File

@ -35,8 +35,8 @@ import { getElementViewLeft } from '../utils'
import PlayerIcon from './aplayer-icon.vue' import PlayerIcon from './aplayer-icon.vue'
defineProps<{ defineProps<{
loadProgress: number, loadProgress: number
playProgress: number, playProgress: number
theme?: string theme?: string
}>() }>()

View File

@ -29,8 +29,8 @@ import IconButton from './aplayer-iconbutton.vue'
import {getElementViewTop} from '../utils' import {getElementViewTop} from '../utils'
const props = defineProps<{ const props = defineProps<{
volume: number, volume: number
muted: boolean, muted: boolean
theme: string theme: string
}>() }>()
const emit = defineEmits(['setvolume']) const emit = defineEmits(['setvolume'])

View File

@ -51,13 +51,13 @@ import Volume from './aplayer-controller-volume.vue'
import { StatType } from '@/model/api/music' import { StatType } from '@/model/api/music'
const props = defineProps<{ const props = defineProps<{
shuffle: boolean, shuffle: boolean
repeat: string, repeat: string
stat: StatType, stat: StatType
theme: string theme: string
volume: number, volume: number
muted: boolean, muted: boolean
showList: boolean, showList: boolean
isMobile: boolean isMobile: boolean
}>() }>()
const loadProgress = computed(() => { const loadProgress = computed(() => {

View File

@ -28,10 +28,10 @@ import { computed } from 'vue'
import { MusicPlayerItem } from '@/model/api/music' import { MusicPlayerItem } from '@/model/api/music'
const props = defineProps<{ const props = defineProps<{
show: boolean, show: boolean
currentMusic: MusicPlayerItem, currentMusic: MusicPlayerItem
musicList: MusicPlayerItem[], musicList: MusicPlayerItem[]
theme?: string, theme?: string
listMaxHeight?: string listMaxHeight?: string
}>() }>()
const listHeightStyle = computed(() => { const listHeightStyle = computed(() => {

View File

@ -21,7 +21,7 @@ import { parseLrc } from '../utils'
import { StatType } from '@/model/api/music' import { StatType } from '@/model/api/music'
const props = defineProps<{ const props = defineProps<{
lrcSource: string, lrcSource: string
playStat: StatType playStat: StatType
}>() }>()

View File

@ -18,8 +18,8 @@ import { computed, ref } from 'vue'
import IconButton from './aplayer-iconbutton.vue' import IconButton from './aplayer-iconbutton.vue'
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
pic?: string, pic?: string
theme?: string, theme?: string
playing: boolean playing: boolean
enableDrag: boolean enableDrag: boolean
}>(), { }>(), {

View File

@ -3,7 +3,7 @@
class="aplayer" class="aplayer"
:class="{ :class="{
'aplayer-narrow': mini, 'aplayer-narrow': mini,
'aplayer-withlist' : !mini && musicList.length > 0, 'aplayer-withlist' : !mini && list.length > 0,
'aplayer-withlrc': !mini && (!!$slots.display || showLrc), 'aplayer-withlrc': !mini && (!!$slots.display || showLrc),
'aplayer-float': isFloatMode, 'aplayer-float': isFloatMode,
'aplayer-loading': isPlaying && isLoading 'aplayer-loading': isPlaying && isLoading
@ -52,7 +52,7 @@
<music-list <music-list
:show="showList && !mini" :show="showList && !mini"
:current-music="currentMusic" :current-music="currentMusic"
:music-list="musicList" :music-list="list"
:play-index="playIndex" :play-index="playIndex"
:listMaxHeight="listMaxHeight" :listMaxHeight="listMaxHeight"
:theme="currentTheme" :theme="currentTheme"
@ -146,7 +146,7 @@
// Audio attributes as props // Audio attributes as props
// since 1.4.0 // since 1.4.0
// autoplay controls muted preload volume // autoplay muted preload volume
// autoplay is not observable // autoplay is not observable
/** /**
@ -158,18 +158,6 @@
default: false, default: false,
}, },
/**
* @since 1.4.0
* whether to show native audio controls below Vue-APlayer
* only work in development environment and not mini mode
*
* observable
*/
controls: {
type: Boolean,
default: false,
},
/** /**
* @since 1.4.0 * @since 1.4.0
* observable, sync * observable, sync
@ -182,7 +170,10 @@
* @since 1.4.0 * @since 1.4.0
* observable * observable
*/ */
preload: String, preload: {
type: String,
default: 'none'
},
/** /**
* @since 1.4.0 * @since 1.4.0
@ -266,6 +257,7 @@
internalRepeat: this.repeat, internalRepeat: this.repeat,
// for shuffling // for shuffling
shuffledList: [], shuffledList: [],
hls: null
} }
}, },
computed: { computed: {
@ -296,13 +288,6 @@
if (this.isMobile) return false if (this.isMobile) return false
return this.autoplay return this.autoplay
}, },
musicList () {
return this.list
},
shouldShowNativeControls () {
return process.env.NODE_ENV !== 'production' &&
this.controls && !this.mini
},
// useful // useful
@ -337,9 +322,6 @@
this.currentMusic = this.shuffledList[val % this.shuffledList.length] this.currentMusic = this.shuffledList[val % this.shuffledList.length]
}, },
}, },
shouldRepeat () {
return this.repeatMode !== REPEAT.NO_REPEAT
},
// since 1.4.0 // since 1.4.0
// sync muted, volume // sync muted, volume
@ -624,7 +606,6 @@
// since 1.4.0 Audio attributes as props // since 1.4.0 Audio attributes as props
this.audio.controls = this.shouldShowNativeControls
this.audio.muted = this.muted this.audio.muted = this.muted
this.audio.preload = this.preload this.audio.preload = this.preload
this.audio.volume = this.volume this.audio.volume = this.volume
@ -738,11 +719,7 @@
}, },
// since 1.4.0 // since 1.4.0
// observe controls, muted, preload, volume // observe muted, preload, volume
shouldShowNativeControls (val) {
this.audio.controls = val
},
isAudioMuted (val) { isAudioMuted (val) {
this.audio.muted = val this.audio.muted = val
}, },
@ -858,11 +835,6 @@
} }
} }
audio[controls] {
display: block;
width: 100%;
}
// Mini mode // Mini mode
&.aplayer-narrow { &.aplayer-narrow {
width: @aplayer-height; width: @aplayer-height;