Skip to content

Commit

Permalink
新增 设置-播放设置-使用设备能处理的最大声道数输出音频 设置(#1873
Browse files Browse the repository at this point in the history
  • Loading branch information
lyswhut committed May 2, 2024
1 parent 793b5a6 commit e4de4b8
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 9 deletions.
2 changes: 2 additions & 0 deletions publish/changeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### 新增

- 新增 设置-播放设置-使用设备能处理的最大声道数输出音频 设置并默认启用(#1873
- 允许添加 `m4a``oga` 格式的本地歌曲到列表中(#1864
- 开放API支持跨域请求(#1872 @Ceale

Expand All @@ -19,6 +20,7 @@
### 变更

- 设置-播放设置-优先播放320k音质选项改为“优先播放的音质”,允许选择更高优先播放的音质,如果歌曲及音源支持的话(#1839
- 设置-播放设置-使用设备能处理的最大声道数输出音频 设置默认启用,此前固定为2声道输出

### 开放API变更

Expand Down
1 change: 1 addition & 0 deletions src/common/defaultSetting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const defaultSetting: LX.AppSetting = {
'player.isMute': false,
'player.playbackRate': 1,
'player.preservesPitch': true,
'player.isMaxOutputChannelCount': true,
'player.mediaDeviceId': 'default',
'player.isMediaDeviceRemovedStopPlay': false,
'player.isShowLyricTranslation': false,
Expand Down
5 changes: 5 additions & 0 deletions src/common/types/app_setting.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ declare global {
*/
'player.preservesPitch': boolean

/**
* 使用设备能处理的最大声道数输出音频
*/
'player.isMaxOutputChannelCount': boolean

/**
* 音频输出设备id
*/
Expand Down
1 change: 1 addition & 0 deletions src/lang/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@
"setting__play_lyric_roma": "Show lyrics roman",
"setting__play_lyric_s2t": "Convert the playing and downloading lyrics to Traditional Chinese",
"setting__play_lyric_transition": "Show lyrics translation",
"setting__play_max_output_channel_count": "Output audio using the maximum number of channels the device can handle",
"setting__play_mediaDevice": "Audio output",
"setting__play_mediaDevice_remove_stop_play": "Pause the song when the current sound output device is changed",
"setting__play_mediaDevice_title": "Select a media device for audio output",
Expand Down
1 change: 1 addition & 0 deletions src/lang/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@
"setting__play_lyric_roma": "显示歌词罗马音(如果可用)",
"setting__play_lyric_s2t": "将播放与下载的歌词转换为繁体中文",
"setting__play_lyric_transition": "显示歌词翻译(如果可用)",
"setting__play_max_output_channel_count": "使用设备能处理的最大声道数输出音频",
"setting__play_mediaDevice": "音频输出",
"setting__play_mediaDevice_remove_stop_play": "当前的声音输出设备被改变时暂停播放歌曲",
"setting__play_mediaDevice_title": "选择声音输出的媒体设备",
Expand Down
1 change: 1 addition & 0 deletions src/lang/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@
"setting__play_lyric_roma": "顯示歌詞羅馬音(如果可用)",
"setting__play_lyric_s2t": "將播放與下載的歌詞轉換為繁體中文",
"setting__play_lyric_transition": "顯示歌詞翻譯(如果可用)",
"setting__play_max_output_channel_count": "使用設備能處理的最大聲道數輸出音頻",
"setting__play_mediaDevice": "音訊輸出",
"setting__play_mediaDevice_remove_stop_play": "當前的聲音輸出裝置被改變時暫停播放歌曲",
"setting__play_mediaDevice_title": "選擇聲音輸出的媒體設備",
Expand Down
14 changes: 14 additions & 0 deletions src/renderer/core/useApp/usePlayer/useMaxOutputChannelCount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { watch } from '@common/utils/vueTools'
import { setMaxOutputChannelCount } from '@renderer/plugins/player'

import { appSetting } from '@renderer/store/setting'

export default () => {
// console.log(appSetting['player.soundEffect.panner.enable'])
setMaxOutputChannelCount(appSetting['player.isMaxOutputChannelCount'])

watch(() => appSetting['player.isMaxOutputChannelCount'], (val) => {
setMaxOutputChannelCount(val)
})
}

18 changes: 9 additions & 9 deletions src/renderer/core/useApp/usePlayer/useMediaDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ export default () => {
})
}

const handleDeviceChangeStopPlay = (label: string) => {
const handleDeviceChange = (label: string) => {
// console.log(device)
// console.log(appSetting['player.isMediaDeviceRemovedStopPlay'], isPlay.value, label, prevDeviceLabel)
if (
appSetting['player.isMediaDeviceRemovedStopPlay'] &&
isPlay.value &&
label != prevDeviceLabel
) {
window.lx.isPlayedStop = true
pause()
if (label != prevDeviceLabel) {
window.app_event.playerDeviceChanged()

if (appSetting['player.isMediaDeviceRemovedStopPlay'] && isPlay.value) {
window.lx.isPlayedStop = true
pause()
}
}
}

const handleMediaListChange = async() => {
const mediaDeviceId = appSetting['player.mediaDeviceId']
const device = await getMediaDevice(mediaDeviceId)

handleDeviceChangeStopPlay(device.label)
handleDeviceChange(device.label)

if (device.deviceId == mediaDeviceId) prevDeviceLabel = device.label
else void setMediaDevice(device.deviceId, device.label)
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/core/useApp/usePlayer/usePlayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { HOTKEY_PLAYER } from '@common/hotKey'
import { playNext, pause, playPrev, togglePlay, collectMusic, uncollectMusic, dislikeMusic } from '@renderer/core/player'
import usePlaybackRate from './usePlaybackRate'
import useSoundEffect from './useSoundEffect'
import useMaxOutputChannelCount from './useMaxOutputChannelCount'
import { setPowerSaveBlocker } from '@renderer/core/player/utils'


Expand All @@ -43,6 +44,7 @@ export default () => {
usePlayEvent()
useLyric()
useVolume()
useMaxOutputChannelCount()
useSoundEffect()
usePlaybackRate()
useWatchList()
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/event/appEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ export class AppEvent extends Event {
this.emit('playerWaiting')
}

playerDeviceChanged() {
this.emit('playerDeviceChanged')
}

// 激活进度条动画事件
activePlayProgressTransition() {
this.emit('activePlayProgressTransition')
Expand Down
28 changes: 28 additions & 0 deletions src/renderer/plugins/player/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ let pitchShifterNode: AudioWorkletNode
let pitchShifterNodePitchFactor: AudioParam
let pitchShifterNodeLoadStatus: 'none' | 'loading' | 'unconnect' | 'connected' = 'none'
let pitchShifterNodeTempValue = 1
let defaultChannelCount = 2
export const soundR = 0.5


Expand Down Expand Up @@ -111,6 +112,7 @@ const initAdvancedAudioFeatures = () => {
if (audioContext) return
if (!audio) throw new Error('audio not defined')
audioContext = new window.AudioContext()
defaultChannelCount = audioContext.destination.channelCount

initAnalyser()
initBiquadFilter()
Expand All @@ -134,6 +136,32 @@ export const getAudioContext = () => {
return audioContext
}

let unsubMediaListChangeEvent: (() => void) | null = null
export const setMaxOutputChannelCount = (enable: boolean) => {
if (enable) {
initAdvancedAudioFeatures()
audioContext.destination.channelCount = audioContext.destination.maxChannelCount
audioContext.destination.channelCountMode = 'max'
// navigator.mediaDevices.addEventListener('devicechange', handleMediaListChange)
if (!unsubMediaListChangeEvent) {
let handleMediaListChange = () => {
setMaxOutputChannelCount(true)
}
window.app_event.on('playerDeviceChanged', handleMediaListChange)
unsubMediaListChangeEvent = () => {
window.app_event.off('playerDeviceChanged', handleMediaListChange)
unsubMediaListChangeEvent = null
}
}
} else {
unsubMediaListChangeEvent?.()
if (audioContext && audioContext.destination.channelCountMode != 'explicit') {
audioContext.destination.channelCount = defaultChannelCount
// audioContext.destination.channelInterpretation
audioContext.destination.channelCountMode = 'explicit'
}
}
}

export const getAnalyser = (): AnalyserNode | null => {
initAdvancedAudioFeatures()
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/views/Setting/components/SettingPlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ dd
base-checkbox(id="setting_player_lyric_play_lxlrc" :model-value="appSetting['player.isPlayLxlrc']" :label="$t('setting__play_lyric_lxlrc')" @update:model-value="updateSetting({'player.isPlayLxlrc': $event})")
.gap-top
base-checkbox(id="setting_player_showTaskProgess" :model-value="appSetting['player.isShowTaskProgess']" :label="$t('setting__play_task_bar')" @update:model-value="updateSetting({'player.isShowTaskProgess': $event})")
.gap-top
base-checkbox(id="setting_player_isMaxOutputChannelCount" :model-value="appSetting['player.isMaxOutputChannelCount']" :label="$t('setting__play_max_output_channel_count')" @update:model-value="updateSetting({'player.isMaxOutputChannelCount': $event})")
.gap-top
base-checkbox(id="setting_player_isMediaDeviceRemovedStopPlay" :model-value="appSetting['player.isMediaDeviceRemovedStopPlay']" :label="$t('setting__play_mediaDevice_remove_stop_play')" @update:model-value="updateSetting({'player.isMediaDeviceRemovedStopPlay': $event})")

Expand Down

0 comments on commit e4de4b8

Please sign in to comment.