Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

快捷键问题 #49

Open
Takenforgranted opened this issue Feb 17, 2024 · 3 comments
Open

快捷键问题 #49

Takenforgranted opened this issue Feb 17, 2024 · 3 comments

Comments

@Takenforgranted
Copy link

这个播放界面不支持一些常规的快捷键比如空格-播放暂停,↑↓-调节音量,←→-前进/后退5/10s以及切换上一首下一首这种,希望后续能有继续的更新。

@lovegaoshi
Copy link
Contributor

@Takenforgranted
Copy link
Author

pr welcome

eg. https://github.com/lovegaoshi/azusa-player/blob/d689d93e4213872eabe8d37de8f0311b425fbdcd/src/components/App/App.tsx#L42

忙,没空改,给个样子吧要是我下午晚上事情多顾不上你就自己改改

// 当用户按下空格键时触发的事件处理函数
useHotkeys('space', () => {
    // 如果当前音频实例为空,直接返回
    if (currentAudioInst === null) return;

    // 如果音频处于暂停状态,则播放;如果正在播放,则暂停
    if (currentAudioInst.paused)
        // @ts-expect-error
        document.getElementsByClassName('music-player-audio')[0].play();
    else
        // @ts-expect-error
        document.getElementsByClassName('music-player-audio')[0].pause();
});

// 当用户按下PageDown键时触发的事件处理函数,用于播放下一首音频
// @ts-expect-error
useHotkeys('arrowdown', () => window.musicplayer.onPlayNextAudio());

// 当用户按下PageUp键时触发的事件处理函数,用于播放上一首音频
// @ts-expect-error
useHotkeys('arrowup', () => window.musicplayer.onPlayPrevAudio());

// 当用户按下右方向键时触发的事件处理函数,用于音频快进5秒
useHotkeys('arrowright', () => {
    if (currentAudioInst === null) return;
    currentAudioInst.currentTime += 5;
});

// 当用户按下左方向键时触发的事件处理函数,用于音频后退5秒
useHotkeys('arrowleft', () => {
    if (currentAudioInst === null) return;
    currentAudioInst.currentTime -= 5;
});

// 当currentAudio的名称发生变化时,更新页面标题
useEffect(() => {
    // 如果currentAudio的名称不存在,直接返回
    if (!currentAudio?.name) return;

    // 更新页面标题为当前音频的名称和应用标题的组合
    document.title = `${currentAudio.name} - ${appTitle}`;
}, [currentAudio?.name]);

@Takenforgranted
Copy link
Author

@lovegaoshi 不得不说,你和我的作息tmd正好相反啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants