mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-05-23 22:37:41 +08:00
音质选择
This commit is contained in:
parent
03a70c8cb0
commit
e1215ce5cf
@ -17,6 +17,7 @@ const defaultSetting: LX.AppSetting = {
|
|||||||
'player.startupAutoPlay': false,
|
'player.startupAutoPlay': false,
|
||||||
'player.togglePlayMethod': 'listLoop',
|
'player.togglePlayMethod': 'listLoop',
|
||||||
'player.isPlayHighQuality': false,
|
'player.isPlayHighQuality': false,
|
||||||
|
'player.playQuality': "128k",
|
||||||
'player.isSavePlayTime': false,
|
'player.isSavePlayTime': false,
|
||||||
'player.volume': 1,
|
'player.volume': 1,
|
||||||
'player.playbackRate': 1,
|
'player.playbackRate': 1,
|
||||||
|
@ -52,7 +52,7 @@ export const getMusicUrl = async ({ musicInfo, quality, isRefresh, allowToggleSo
|
|||||||
|
|
||||||
// // return Promise.reject(new Error('该歌曲没有可播放的音频'))
|
// // return Promise.reject(new Error('该歌曲没有可播放的音频'))
|
||||||
// }
|
// }
|
||||||
const targetQuality = quality ?? getPlayQuality(settingState.setting['player.isPlayHighQuality'], musicInfo)
|
const targetQuality = quality ?? getPlayQuality(settingState.setting['player.playQuality'], musicInfo)
|
||||||
const cachedUrl = await getStoreMusicUrl(musicInfo, targetQuality)
|
const cachedUrl = await getStoreMusicUrl(musicInfo, targetQuality)
|
||||||
if (cachedUrl && !isRefresh) return cachedUrl
|
if (cachedUrl && !isRefresh) return cachedUrl
|
||||||
|
|
||||||
|
@ -208,10 +208,17 @@ export const getOnlineOtherSourcePicByLocal = async (musicInfo: LX.Music.MusicIn
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getPlayQuality = (highQuality: boolean, musicInfo: LX.Music.MusicInfoOnline): LX.Quality => {
|
// export const getPlayQuality = (highQuality: boolean, musicInfo: LX.Music.MusicInfoOnline): LX.Quality => {
|
||||||
|
// let type: LX.Quality = '128k'
|
||||||
|
// let list = global.lx.qualityList[musicInfo.source]
|
||||||
|
// if (highQuality && musicInfo.meta._qualitys['flac'] && list && list.includes('flac')) type = 'flac'
|
||||||
|
// return type
|
||||||
|
// }
|
||||||
|
|
||||||
|
export const getPlayQuality = (playQuality: LX.Quality, musicInfo: LX.Music.MusicInfoOnline): LX.Quality => {
|
||||||
let type: LX.Quality = '128k'
|
let type: LX.Quality = '128k'
|
||||||
let list = global.lx.qualityList[musicInfo.source]
|
let list = global.lx.qualityList[musicInfo.source]
|
||||||
if (highQuality && musicInfo.meta._qualitys['flac'] && list && list.includes('flac')) type = 'flac'
|
if (musicInfo.meta._qualitys[playQuality] && list && list.includes(playQuality)) type = playQuality
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +243,8 @@ export const getOnlineOtherSourceMusicUrl = async ({ musicInfos, quality, onTogg
|
|||||||
if (retryedSource.includes(musicInfo.source)) continue
|
if (retryedSource.includes(musicInfo.source)) continue
|
||||||
retryedSource.push(musicInfo.source)
|
retryedSource.push(musicInfo.source)
|
||||||
if (!assertApiSupport(musicInfo.source)) continue
|
if (!assertApiSupport(musicInfo.source)) continue
|
||||||
itemQuality = quality ?? getPlayQuality(settingState.setting['player.isPlayHighQuality'], musicInfo)
|
// itemQuality = quality ?? getPlayQuality(settingState.setting['player.isPlayHighQuality'], musicInfo)
|
||||||
|
itemQuality = quality ?? getPlayQuality(settingState.setting['player.playQuality'], musicInfo)
|
||||||
if (!musicInfo.meta._qualitys[itemQuality]) continue
|
if (!musicInfo.meta._qualitys[itemQuality]) continue
|
||||||
|
|
||||||
console.log('try toggle to: ', musicInfo.source, musicInfo.name, musicInfo.singer, musicInfo.interval)
|
console.log('try toggle to: ', musicInfo.source, musicInfo.name, musicInfo.singer, musicInfo.interval)
|
||||||
@ -283,7 +291,7 @@ export const handleGetOnlineMusicUrl = async ({ musicInfo, quality, onToggleSour
|
|||||||
}> => {
|
}> => {
|
||||||
if (!await global.lx.apiInitPromise[0]) throw new Error('source init failed')
|
if (!await global.lx.apiInitPromise[0]) throw new Error('source init failed')
|
||||||
// console.log(musicInfo.source)
|
// console.log(musicInfo.source)
|
||||||
const targetQuality = quality ?? getPlayQuality(settingState.setting['player.isPlayHighQuality'], musicInfo)
|
const targetQuality = quality ?? getPlayQuality(settingState.setting['player.playQuality'], musicInfo)
|
||||||
|
|
||||||
let reqPromise
|
let reqPromise
|
||||||
try {
|
try {
|
||||||
|
@ -334,6 +334,7 @@
|
|||||||
"setting_play_auto_clean_played_list": "Automatically clear the played list",
|
"setting_play_auto_clean_played_list": "Automatically clear the played list",
|
||||||
"setting_play_auto_clean_played_list_tip": "In random play mode, when switching songs by clicking the same list as the playlist, if automatic clearing of the already played list is enabled, the played songs will re-participate in random play.",
|
"setting_play_auto_clean_played_list_tip": "In random play mode, when switching songs by clicking the same list as the playlist, if automatic clearing of the already played list is enabled, the played songs will re-participate in random play.",
|
||||||
"setting_play_cache_size": "Maximum cache size (MB)",
|
"setting_play_cache_size": "Maximum cache size (MB)",
|
||||||
|
"setting_play_select": "Select sound quality listening",
|
||||||
"setting_play_cache_size_no_cache": "Disabled cache",
|
"setting_play_cache_size_no_cache": "Disabled cache",
|
||||||
"setting_play_cache_size_save_tip": "The cache setting is completed, it will take effect after restarting the application",
|
"setting_play_cache_size_save_tip": "The cache setting is completed, it will take effect after restarting the application",
|
||||||
"setting_play_handle_audio_focus": "When other apps play sound, automatically pause the playback",
|
"setting_play_handle_audio_focus": "When other apps play sound, automatically pause the playback",
|
||||||
|
@ -334,6 +334,7 @@
|
|||||||
"setting_play_auto_clean_played_list": "自动清空已播放列表",
|
"setting_play_auto_clean_played_list": "自动清空已播放列表",
|
||||||
"setting_play_auto_clean_played_list_tip": "随机播放模式下,通过 「点击」 与 「播放列表相同的列表内的歌曲」 切歌时,若启用 「自动清空已播放列表」,则已播放的歌曲将重新参与随机播放。",
|
"setting_play_auto_clean_played_list_tip": "随机播放模式下,通过 「点击」 与 「播放列表相同的列表内的歌曲」 切歌时,若启用 「自动清空已播放列表」,则已播放的歌曲将重新参与随机播放。",
|
||||||
"setting_play_cache_size": "最大缓存大小(MB)",
|
"setting_play_cache_size": "最大缓存大小(MB)",
|
||||||
|
"setting_play_select": "播放音质选择",
|
||||||
"setting_play_cache_size_no_cache": "禁用缓存",
|
"setting_play_cache_size_no_cache": "禁用缓存",
|
||||||
"setting_play_cache_size_save_tip": "缓存设置完毕,重启应用后生效",
|
"setting_play_cache_size_save_tip": "缓存设置完毕,重启应用后生效",
|
||||||
"setting_play_handle_audio_focus": "其他应用播放声音时,自动暂停播放",
|
"setting_play_handle_audio_focus": "其他应用播放声音时,自动暂停播放",
|
||||||
|
@ -46,7 +46,7 @@ export default memo(() => {
|
|||||||
|
|
||||||
const styles = createStyle({
|
const styles = createStyle({
|
||||||
content: {
|
content: {
|
||||||
marginTop: 10,
|
marginTop: 0,
|
||||||
marginBottom: 15,
|
marginBottom: 15,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -0,0 +1,90 @@
|
|||||||
|
import { memo, useEffect, useMemo, useState } from 'react'
|
||||||
|
import { View } from 'react-native'
|
||||||
|
|
||||||
|
import InputItem, { type InputItemProps } from '../../components/InputItem'
|
||||||
|
import { createStyle, toast } from '@/utils/tools'
|
||||||
|
import { useSettingValue } from '@/store/setting/hook'
|
||||||
|
import { useI18n } from '@/lang'
|
||||||
|
import { updateSetting } from '@/core/common'
|
||||||
|
import CheckBox from '@/components/common/CheckBox'
|
||||||
|
import SubTitle from '../../components/SubTitle'
|
||||||
|
import settingState from '@/store/setting/state'
|
||||||
|
|
||||||
|
const MAX_SIZE = 1024 * 1024 * 1024
|
||||||
|
export default memo(() => {
|
||||||
|
const t = useI18n()
|
||||||
|
const [playQualityList, setPlayQualityList] = useState<MusicOption[]>([]);
|
||||||
|
useEffect(() => {
|
||||||
|
setPlayQualityList([
|
||||||
|
{
|
||||||
|
id: "128k",
|
||||||
|
key: "128k",
|
||||||
|
name: "标准音质"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "320k",
|
||||||
|
key: "320k",
|
||||||
|
name: "高品音质"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "flac",
|
||||||
|
key: "flac",
|
||||||
|
name: "无损音质"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "flac24bit",
|
||||||
|
key: "flac24bit",
|
||||||
|
name: "Hi-Res音质"
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
}, [])
|
||||||
|
const [selectedQuality, setSelectedQuality] = useState<LX.Quality>(useSettingValue('player.playQuality'));
|
||||||
|
|
||||||
|
const setPlayQuality = (playQuality: LX.Quality) => {
|
||||||
|
updateSetting({ 'player.playQuality': playQuality })
|
||||||
|
setSelectedQuality(playQuality);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MusicOption {
|
||||||
|
id: LX.Quality;
|
||||||
|
name: string;
|
||||||
|
size?: string | null;
|
||||||
|
key?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const useActive = (id: LX.Quality) => {
|
||||||
|
const isActive = useMemo(() => selectedQuality == id, [selectedQuality, id])
|
||||||
|
return isActive
|
||||||
|
}
|
||||||
|
|
||||||
|
const Item = ({ id, name }: {
|
||||||
|
id: LX.Quality
|
||||||
|
name: string
|
||||||
|
}) => {
|
||||||
|
const isActive = useActive(id)
|
||||||
|
return <CheckBox marginRight={8} check={isActive} label={name} onChange={() => { setPlayQuality(id) }} need />
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.content} >
|
||||||
|
<SubTitle title={t('setting_play_select')}>
|
||||||
|
<View style={styles.list}>
|
||||||
|
{
|
||||||
|
playQualityList.map((item) => <Item name={item.name} id={item.id} key={item.key} />)
|
||||||
|
}
|
||||||
|
</View>
|
||||||
|
</SubTitle>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const styles = createStyle({
|
||||||
|
content: {
|
||||||
|
marginTop: 10,
|
||||||
|
},
|
||||||
|
list: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
flexWrap: 'nowrap',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
@ -9,6 +9,7 @@ import IsAutoCleanPlayedList from './IsAutoCleanPlayedList'
|
|||||||
import IsShowNotificationImage from './IsShowNotificationImage'
|
import IsShowNotificationImage from './IsShowNotificationImage'
|
||||||
import IsShowLyricTranslation from './IsShowLyricTranslation'
|
import IsShowLyricTranslation from './IsShowLyricTranslation'
|
||||||
import IsShowLyricRoma from './IsShowLyricRoma'
|
import IsShowLyricRoma from './IsShowLyricRoma'
|
||||||
|
import SelectPlayQuality from './SelectPlayQuality'
|
||||||
import IsS2T from './IsS2T'
|
import IsS2T from './IsS2T'
|
||||||
import MaxCache from './MaxCache'
|
import MaxCache from './MaxCache'
|
||||||
import { useI18n } from '@/lang'
|
import { useI18n } from '@/lang'
|
||||||
@ -21,13 +22,14 @@ export default memo(() => {
|
|||||||
<Section title={t('setting_player')}>
|
<Section title={t('setting_player')}>
|
||||||
<IsSavePlayTime />
|
<IsSavePlayTime />
|
||||||
<IsAutoCleanPlayedList />
|
<IsAutoCleanPlayedList />
|
||||||
<IsPlayHighQuality />
|
{/* <IsPlayHighQuality /> */}
|
||||||
<IsHandleAudioFocus />
|
<IsHandleAudioFocus />
|
||||||
<IsEnableAudioOffload />
|
<IsEnableAudioOffload />
|
||||||
<IsShowNotificationImage />
|
<IsShowNotificationImage />
|
||||||
<IsShowLyricTranslation />
|
<IsShowLyricTranslation />
|
||||||
<IsShowLyricRoma />
|
<IsShowLyricRoma />
|
||||||
<IsS2T />
|
<IsS2T />
|
||||||
|
<SelectPlayQuality />
|
||||||
<MaxCache />
|
<MaxCache />
|
||||||
</Section>
|
</Section>
|
||||||
)
|
)
|
||||||
|
1
src/types/common.d.ts
vendored
1
src/types/common.d.ts
vendored
@ -4,6 +4,7 @@ declare namespace LX {
|
|||||||
type OnlineSource = 'kw' | 'kg' | 'tx' | 'wy' | 'mg'
|
type OnlineSource = 'kw' | 'kg' | 'tx' | 'wy' | 'mg'
|
||||||
type Source = OnlineSource | 'local'
|
type Source = OnlineSource | 'local'
|
||||||
type Quality = '128k' | '320k' | 'flac' | 'flac24bit' | '192k' | 'ape' | 'wav'
|
type Quality = '128k' | '320k' | 'flac' | 'flac24bit' | '192k' | 'ape' | 'wav'
|
||||||
|
type
|
||||||
type QualityList = Partial<Record<LX.Source, LX.Quality[]>>
|
type QualityList = Partial<Record<LX.Source, LX.Quality[]>>
|
||||||
|
|
||||||
type ShareType = 'system' | 'clipboard'
|
type ShareType = 'system' | 'clipboard'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user