新增Scheme URL对播放器的控制操作

pull/1583/head
lyswhut 2023-09-14 17:19:13 +08:00
parent aabd6d8985
commit 0b125e29b5
5 changed files with 74 additions and 23 deletions

View File

@ -1,9 +1,9 @@
目前本项目的原始发布地址只有 **GitHub****蓝奏网盘** ,其他渠道均为第三方转载发布,可信度请自行鉴别。
本项目无微信公众号之类的官方账号,谨防被骗。
### 修复
### 新增
- 修复 v2.4.0 的默认数据库版本号不对导致首次安装该版本的用户无法再次启动软件的问题
- 新增Scheme URL对播放器的控制操作新增的操作包含 播放、暂停、下一首、上一首等详情看Scheme URL文档
### 其他

View File

@ -17,6 +17,9 @@ import { getMusicUrl, getPicPath, getLyricInfo } from '../music/index'
import { filterList } from './utils'
import { requestMsg } from '@renderer/utils/message'
import { getRandom } from '@renderer/utils/index'
import { addListMusics, removeListMusics } from '@renderer/store/list/action'
import { loveList } from '@renderer/store/list/state'
import { addDislikeInfo } from '@renderer/core/dislikeList'
// import { checkMusicFileAvailable } from '@renderer/utils/music'
let gettingUrlId = ''
@ -488,3 +491,29 @@ export const togglePlay = () => {
play()
}
}
/**
*
*/
export const collectMusic = () => {
if (!playMusicInfo.musicInfo) return
void addListMusics(loveList.id, ['progress' in playMusicInfo.musicInfo ? playMusicInfo.musicInfo.metadata.musicInfo : playMusicInfo.musicInfo])
}
/**
*
*/
export const uncollectMusic = () => {
if (!playMusicInfo.musicInfo) return
void removeListMusics({ listId: loveList.id, ids: ['progress' in playMusicInfo.musicInfo ? playMusicInfo.musicInfo.metadata.musicInfo.id : playMusicInfo.musicInfo.id] })
}
/**
*
*/
export const dislikeMusic = async() => {
if (!playMusicInfo.musicInfo) return
const minfo = 'progress' in playMusicInfo.musicInfo ? playMusicInfo.musicInfo.metadata.musicInfo : playMusicInfo.musicInfo
await addDislikeInfo([{ name: minfo.name, singer: minfo.singer }])
await playNext(true)
}

View File

@ -4,6 +4,7 @@ import { clearEnvParamsDeeplink, focusWindow, onDeeplink } from '@renderer/utils
import { useDialog } from './utils'
import useMusicAction from './useMusicAction'
import useSonglistAction from './useSonglistAction'
import usePlayerAction from './usePlayerAction'
export default () => {
let isInited = false
@ -12,6 +13,7 @@ export default () => {
const handleMusicAction = useMusicAction()
const handleSonglistAction = useSonglistAction()
const handlePlayerAction = usePlayerAction()
const handleLinkAction = async(link: string) => {
@ -41,6 +43,9 @@ export default () => {
case 'songlist':
await handleSonglistAction(action, params)
break
case 'player':
await handlePlayerAction(action as any)
break
default: throw new Error('Unknown type: ' + type)
}
}

View File

@ -0,0 +1,35 @@
import { collectMusic, dislikeMusic, pause, play, playNext, playPrev, togglePlay, uncollectMusic } from '@renderer/core/player'
type Action = 'play' | 'pause' | 'skipNext' | 'skipPrev' | 'togglePlay' | 'collect' | 'uncollect' | 'dislike'
export default () => {
return async(action: Action) => {
switch (action) {
case 'play':
play()
break
case 'pause':
pause()
break
case 'skipNext':
playNext()
break
case 'skipPrev':
playPrev()
break
case 'togglePlay':
togglePlay()
break
case 'collect':
collectMusic()
break
case 'uncollect':
uncollectMusic()
break
case 'dislike':
dislikeMusic()
break
default: throw new Error('Unknown action: ' + (action as any ?? ''))
}
}
}

View File

@ -29,12 +29,9 @@ import useLyric from './useLyric'
import useVolume from './useVolume'
import useWatchList from './useWatchList'
import { HOTKEY_PLAYER } from '@common/hotKey'
import { playNext, pause, playPrev, togglePlay } from '@renderer/core/player'
import { playNext, pause, playPrev, togglePlay, collectMusic, uncollectMusic, dislikeMusic } from '@renderer/core/player'
import usePlaybackRate from './usePlaybackRate'
import useSoundEffect from './useSoundEffect'
import { addListMusics, removeListMusics } from '@renderer/store/list/action'
import { loveList } from '@renderer/store/list/state'
import { addDislikeInfo } from '@renderer/core/dislikeList'
export default () => {
@ -93,21 +90,6 @@ export default () => {
setStop()
}
const collectMusic = () => {
if (!playMusicInfo.musicInfo) return
void addListMusics(loveList.id, ['progress' in playMusicInfo.musicInfo ? playMusicInfo.musicInfo.metadata.musicInfo : playMusicInfo.musicInfo])
}
const unCollectMusic = () => {
if (!playMusicInfo.musicInfo) return
void removeListMusics({ listId: loveList.id, ids: ['progress' in playMusicInfo.musicInfo ? playMusicInfo.musicInfo.metadata.musicInfo.id : playMusicInfo.musicInfo.id] })
}
const dislikeMusic = async() => {
if (!playMusicInfo.musicInfo) return
const minfo = 'progress' in playMusicInfo.musicInfo ? playMusicInfo.musicInfo.metadata.musicInfo : playMusicInfo.musicInfo
await addDislikeInfo([{ name: minfo.name, singer: minfo.singer }])
playNext(true)
}
watch(() => appSetting['player.togglePlayMethod'], newValue => {
// setLoopPlay(newValue == 'singleLoop')
if (playedList.length) clearPlayedList()
@ -121,7 +103,7 @@ export default () => {
window.key_event.on(HOTKEY_PLAYER.prev.action, handlePlayPrev)
window.key_event.on(HOTKEY_PLAYER.toggle_play.action, togglePlay)
window.key_event.on(HOTKEY_PLAYER.music_love.action, collectMusic)
window.key_event.on(HOTKEY_PLAYER.music_unlove.action, unCollectMusic)
window.key_event.on(HOTKEY_PLAYER.music_unlove.action, uncollectMusic)
window.key_event.on(HOTKEY_PLAYER.music_dislike.action, dislikeMusic)
window.app_event.on('play', setPlayStatus)
@ -141,7 +123,7 @@ export default () => {
window.key_event.off(HOTKEY_PLAYER.prev.action, handlePlayPrev)
window.key_event.off(HOTKEY_PLAYER.toggle_play.action, togglePlay)
window.key_event.off(HOTKEY_PLAYER.music_love.action, collectMusic)
window.key_event.off(HOTKEY_PLAYER.music_unlove.action, unCollectMusic)
window.key_event.off(HOTKEY_PLAYER.music_unlove.action, uncollectMusic)
window.key_event.off(HOTKEY_PLAYER.music_dislike.action, dislikeMusic)