Skip to content

Commit

Permalink
feat: support random play
Browse files Browse the repository at this point in the history
  • Loading branch information
Linkontoask committed Feb 8, 2021
1 parent 3badf6b commit 2d486e3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/iconfont/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import $script from 'scriptjs'
import { noop } from '@/utils/index'

const ICONFONT_URL = 'font_2132275_73mcnctm9yy'
const ICONFONT_URL = 'font_2132275_ypy5tdama8'

// repair electron packaging '//' protocol problem
$script(`https://at.alicdn.com/t/${ICONFONT_URL}.js`, noop)
Expand Down
19 changes: 11 additions & 8 deletions src/pages/footer/components/music-controller/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
FooterActions,
FooterMutations,
Direction,
BasicEffect
BasicEffect,
PlayMode
} from '@/interface'
import { Platform } from '@/config/build'
import { asyncIpc, asyncIpcOrigin } from '@/electron/event/ipc-browser'
Expand Down Expand Up @@ -58,6 +59,12 @@ export const MusicControl = defineComponent({
return formatTime(currentTime.value, 's')
})

const changePlayMode = () => {
useMutations(
FooterMutations.CHANGE_PLAYMODE,
playMode.value === PlayMode.RANDOM ? PlayMode.TURN : PlayMode.RANDOM
)
}
const prevMusic = () => {
useActions(FooterActions.CUTOVER_TRACK, Direction.PREV)
}
Expand Down Expand Up @@ -243,20 +250,16 @@ export const MusicControl = defineComponent({
></audio>
<div class={`${prefix}-command-center`}>
<div class={`${prefix}-command-group`}>
<ve-button type="text">
<ve-button type="text" onClick={changePlayMode}>
<icon
icon={playMode.value}
color="#333"
size={16}
aria-title="播放顺序"
></icon>
</ve-button>
<ve-button type="text" class="theme-btn-color">
<icon
icon="shangyishou"
aria-title="上一首"
onClick={prevMusic}
></icon>
<ve-button type="text" class="theme-btn-color" onClick={prevMusic}>
<icon icon="shangyishou" aria-title="上一首"></icon>
</ve-button>
<ve-button
type="text"
Expand Down
6 changes: 4 additions & 2 deletions src/pages/footer/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export const enum BasicEffect {
}

export const enum PlayMode {
TURN = 'turn'
TURN = 'turn',
RANDOM = 'random'
}

export const enum Direction {
Expand Down Expand Up @@ -84,5 +85,6 @@ export const enum FooterMutations {
LYRICE_EMBED_MIN_WIDTH = 'LYRICE_EMBED_MIN_WIDTH',
SEEKBACKWARD = 'SEEKBACKWARD',
SEEKFORWARD = 'SEEKFORWARD',
INIT_EFFECT = 'INIT_EFFECT'
INIT_EFFECT = 'INIT_EFFECT',
CHANGE_PLAYMODE = 'CHANGE_PLAYMODE'
}
7 changes: 6 additions & 1 deletion src/pages/footer/sage.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { toRaw } from 'vue'
import { ActionTree, MutationTree, GetterTree } from 'vuex'
import { isNumber, timeTos, toFixed } from '@/utils/index'
import { isNumber, timeTos, toFixed, renderRandom } from '@/utils/index'
import { getSongDetail, getLyric } from '@/api/index'
import {
FooterState,
Expand Down Expand Up @@ -184,6 +184,8 @@ export const actions: ActionTree<FooterState, RootState> = {
next = index === state.musicStack.length - 1 ? 0 : index + 1
}
break
case PlayMode.RANDOM:
next = renderRandom(state.musicStack.length, index)
}
const nextMusic = state.musicStack[next]

Expand Down Expand Up @@ -297,5 +299,8 @@ export const mutations: MutationTree<FooterState> = {
if (state.audioElement) {
state.effect = new AudioEffect(state.audioElement)
}
},
[FooterMutations.CHANGE_PLAYMODE](state, mode: PlayMode) {
state.playMode = mode
}
}
4 changes: 2 additions & 2 deletions src/pages/header/component/setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ export const Setting = defineComponent({
}

return () => (
<div class="setting">
<div class="setting vchj">
<ve-button
type="text"
class="header-window-btn"
onClick={handleOpenSetting}
>
<icon icon="setting"></icon>
<icon icon="setting-new" size={25}></icon>
</ve-button>
<ve-button type="text" class="header-window-btn">
<Popover
Expand Down
12 changes: 12 additions & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,15 @@ export const scrollAnmation = (
}
step()
}

export const renderRandom = (extent: number, index: number) => {
if (extent <= 1) return extent
const random = (): number => {
const n = Math.floor(Math.random() * extent)
if (n !== index) {
return n
}
return random()
}
return random()
}

0 comments on commit 2d486e3

Please sign in to comment.