-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: mpris support * fix: 修复网页版无法播放 * fix: 修复在 Player.js 里 ipcRenderer 为空时引发的错误 * docs: update README * docs: update README Co-authored-by: memorydream <[email protected]>
- Loading branch information
1 parent
5a5fb1f
commit d15b58d
Showing
9 changed files
with
235 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ | |
- 🟥 支持 Last.fm Scrobble | ||
- ☁️ 支持音乐云盘 | ||
- ⌨️ 自定义快捷键和全局快捷键 | ||
- 🎧 支持Mpris | ||
- 🛠 更多特性开发中 | ||
|
||
## 📦️ 安装 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { ipcMain, app } from 'electron'; | ||
|
||
export function createMpris(window) { | ||
const Player = require('mpris-service'); | ||
const renderer = window.webContents; | ||
|
||
const player = Player({ | ||
name: 'yesplaymusic', | ||
identity: 'YesPlayMusic', | ||
}); | ||
|
||
player.on('next', () => renderer.send('next')); | ||
player.on('previous', () => renderer.send('previous')); | ||
player.on('playpause', () => renderer.send('play')); | ||
player.on('play', () => renderer.send('play')); | ||
player.on('pause', () => renderer.send('play')); | ||
player.on('quit', () => app.exit()); | ||
player.on('position', args => | ||
renderer.send('setPosition', args.position / 1000 / 1000) | ||
); | ||
player.on('loopStatus', () => renderer.send('repeat')); | ||
player.on('shuffle', () => renderer.send('shuffle')); | ||
|
||
ipcMain.on('player', (e, { playing }) => { | ||
player.playbackStatus = playing | ||
? Player.PLAYBACK_STATUS_PLAYING | ||
: Player.PLAYBACK_STATUS_PAUSED; | ||
}); | ||
|
||
ipcMain.on('metadata', (e, metadata) => { | ||
player.metadata = { | ||
'mpris:trackid': player.objectPath('track/' + metadata.trackId), | ||
'mpris:artUrl': metadata.artwork[0].src, | ||
'mpris:length': metadata.length * 1000 * 1000, | ||
'xesam:title': metadata.title, | ||
'xesam:album': metadata.album, | ||
'xesam:artist': metadata.artist.split(','), | ||
}; | ||
}); | ||
|
||
ipcMain.on('playerCurrentTrackTime', (e, position) => { | ||
player.getPosition = () => position * 1000 * 1000; | ||
}); | ||
|
||
ipcMain.on('switchRepeatMode', (e, mode) => { | ||
switch (mode) { | ||
case 'off': | ||
player.loopStatus = Player.LOOP_STATUS_NONE; | ||
break; | ||
case 'one': | ||
player.loopStatus = Player.LOOP_STATUS_TRACK; | ||
break; | ||
case 'on': | ||
player.loopStatus = Player.LOOP_STATUS_PLAYLIST; | ||
break; | ||
} | ||
}); | ||
|
||
ipcMain.on('switchShuffle', (e, shuffle) => { | ||
player.shuffle = shuffle; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.