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
ade8d4f2df
commit
cda9302eb3
16
package-lock.json
generated
16
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "lx-music-mobile",
|
||||
"version": "1.7.0-beta.0",
|
||||
"version": "1.7.0-beta.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "lx-music-mobile",
|
||||
"version": "1.7.0-beta.0",
|
||||
"version": "1.7.0-beta.1",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@craftzdog/react-native-buffer": "^6.0.5",
|
||||
@ -29,7 +29,7 @@
|
||||
"react-native-pager-view": "6.3.0",
|
||||
"react-native-quick-base64": "^2.1.2",
|
||||
"react-native-quick-md5": "^3.0.6",
|
||||
"react-native-track-player": "github:lyswhut/react-native-track-player#930681ab40fdb50f3d0eedff6ecd29b1666fd3ff",
|
||||
"react-native-track-player": "github:lyswhut/react-native-track-player#23ad66e239170bd9be1b21047f50150ea26f8fd0",
|
||||
"react-native-vector-icons": "^10.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
@ -10873,8 +10873,8 @@
|
||||
},
|
||||
"node_modules/react-native-track-player": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "git+ssh://git@github.com/lyswhut/react-native-track-player.git#930681ab40fdb50f3d0eedff6ecd29b1666fd3ff",
|
||||
"integrity": "sha512-i268ePGmDQvImXWi7mRttFnyA3ReIoMY12/40g4qj1OQgkDScDi/00O0QCYfL3pHCQc36pfi40GWNLM4i02Ziw==",
|
||||
"resolved": "git+ssh://git@github.com/lyswhut/react-native-track-player.git#23ad66e239170bd9be1b21047f50150ea26f8fd0",
|
||||
"integrity": "sha512-TLiUKfi3LCAzNxv+Qk9a6QCDEaZh2TiCYmqb/dsLqDbXhUnv2KHRBS9f3/IE6n+xXBzOnk5/8khHgn95SSvhRw==",
|
||||
"license": "Apache-2.0",
|
||||
"peerDependencies": {
|
||||
"react": ">=16.8.6",
|
||||
@ -21483,9 +21483,9 @@
|
||||
}
|
||||
},
|
||||
"react-native-track-player": {
|
||||
"version": "git+ssh://git@github.com/lyswhut/react-native-track-player.git#930681ab40fdb50f3d0eedff6ecd29b1666fd3ff",
|
||||
"integrity": "sha512-i268ePGmDQvImXWi7mRttFnyA3ReIoMY12/40g4qj1OQgkDScDi/00O0QCYfL3pHCQc36pfi40GWNLM4i02Ziw==",
|
||||
"from": "react-native-track-player@github:lyswhut/react-native-track-player#930681ab40fdb50f3d0eedff6ecd29b1666fd3ff",
|
||||
"version": "git+ssh://git@github.com/lyswhut/react-native-track-player.git#23ad66e239170bd9be1b21047f50150ea26f8fd0",
|
||||
"integrity": "sha512-TLiUKfi3LCAzNxv+Qk9a6QCDEaZh2TiCYmqb/dsLqDbXhUnv2KHRBS9f3/IE6n+xXBzOnk5/8khHgn95SSvhRw==",
|
||||
"from": "react-native-track-player@github:lyswhut/react-native-track-player#23ad66e239170bd9be1b21047f50150ea26f8fd0",
|
||||
"requires": {}
|
||||
},
|
||||
"react-native-vector-icons": {
|
||||
|
@ -64,7 +64,7 @@
|
||||
"react-native-pager-view": "6.3.0",
|
||||
"react-native-quick-base64": "^2.1.2",
|
||||
"react-native-quick-md5": "^3.0.6",
|
||||
"react-native-track-player": "github:lyswhut/react-native-track-player#930681ab40fdb50f3d0eedff6ecd29b1666fd3ff",
|
||||
"react-native-track-player": "github:lyswhut/react-native-track-player#23ad66e239170bd9be1b21047f50150ea26f8fd0",
|
||||
"react-native-vector-icons": "^10.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -1,16 +1,22 @@
|
||||
为了防止歌曲缓存被当做第三方软件当做垃圾意外清理,歌曲缓存地址不再存储到缓存目录,若想清理缓存,需去 设置-其他-资源缓存管理 清理。
|
||||
|
||||
更新到该版本首次播放歌曲时,会将之前的歌曲缓存迁移到新位置,需要等待的时间取决于你已缓存资源的大小。
|
||||
|
||||
### 新增
|
||||
|
||||
- 新增蓝牙歌词支持,可以去 设置-播放设置-显示蓝牙歌词 启用(#615)
|
||||
|
||||
### 优化
|
||||
|
||||
- 防止歌曲缓存被当做第三方软件当做垃圾意外清理
|
||||
- 优化正常播放结束时的下一首歌曲播放衔接度,在歌曲即将播放结束时将预获取下一首歌曲的播放链接,减少自动切歌时的等待时间
|
||||
- 首次使用的提示窗口可以点击背景或者返回键关闭(#577)
|
||||
- 上移 Toast 位置避免遮挡播放模式图标(#603 @sibojia)
|
||||
|
||||
### 变更
|
||||
|
||||
- 不再缓存换源歌曲信息
|
||||
- 歌曲缓存地址不再存储到缓存目录
|
||||
- 不再长期缓存换源歌曲信息
|
||||
|
||||
### 其他
|
||||
|
||||
|
@ -2,6 +2,7 @@ import { getMusicUrl } from '@/core/music'
|
||||
import { getNextPlayMusicInfo, resetRandomNextMusicInfo } from '@/core/player/player'
|
||||
import { checkUrl } from '@/utils/request'
|
||||
import playerState from '@/store/player/state'
|
||||
import { isCached } from '@/plugins/player/utils'
|
||||
|
||||
|
||||
const preloadMusicInfo = {
|
||||
@ -24,8 +25,8 @@ const preloadNextMusicUrl = async(curTime: number) => {
|
||||
const url = await getMusicUrl({ musicInfo: info.musicInfo }).catch(() => '')
|
||||
if (url) {
|
||||
console.log('preload url', url)
|
||||
const result = await checkUrl(url).then(() => true).catch(() => false)
|
||||
if (!result) {
|
||||
const [cached, available] = await Promise.all([isCached(url), checkUrl(url).then(() => true).catch(() => false)])
|
||||
if (!cached && !available) {
|
||||
const url = await getMusicUrl({ musicInfo: info.musicInfo, isRefresh: true }).catch(() => '')
|
||||
console.log('preload url refresh', url)
|
||||
}
|
||||
|
@ -201,6 +201,7 @@
|
||||
"player__geting_url_delay_retry": "The server is busy, try again in {time} seconds...",
|
||||
"player__loading": "Music loading...",
|
||||
"player__refresh_url": "The URL has expired, refreshing the URL...",
|
||||
"player_cache_migrating": "Song cache is being migrated, please wait ⌛️",
|
||||
"quality_high_quality": "HQ",
|
||||
"quality_lossless": "SQ",
|
||||
"quality_lossless_24bit": "Hires",
|
||||
|
@ -201,6 +201,7 @@
|
||||
"player__geting_url_delay_retry": "服务器繁忙,{time}秒后重试...",
|
||||
"player__loading": "音乐加载中...",
|
||||
"player__refresh_url": "URL过期,正在刷新URL...",
|
||||
"player_cache_migrating": "歌曲缓存迁移中,请稍等 ⌛️",
|
||||
"quality_high_quality": "HQ",
|
||||
"quality_lossless": "SQ",
|
||||
"quality_lossless_24bit": "Hires",
|
||||
|
@ -1,5 +1,5 @@
|
||||
import TrackPlayer from 'react-native-track-player'
|
||||
import { updateOptions, setVolume, setPlaybackRate } from './utils'
|
||||
import { updateOptions, setVolume, setPlaybackRate, migratePlayerCache } from './utils'
|
||||
|
||||
// const listenEvent = () => {
|
||||
// TrackPlayer.addEventListener('playback-error', err => {
|
||||
@ -26,6 +26,7 @@ const initial = async({ volume, playRate, cacheSize, isHandleAudioFocus, isEnabl
|
||||
if (global.lx.playerStatus.isIniting || global.lx.playerStatus.isInitialized) return
|
||||
global.lx.playerStatus.isIniting = true
|
||||
console.log('Cache Size', cacheSize * 1024)
|
||||
await migratePlayerCache()
|
||||
await TrackPlayer.setupPlayer({
|
||||
maxCacheSize: cacheSize * 1024,
|
||||
maxBuffer: 1000,
|
||||
|
@ -1,6 +1,8 @@
|
||||
import TrackPlayer, { Capability, Event, RepeatMode, State } from 'react-native-track-player'
|
||||
import BackgroundTimer from 'react-native-background-timer'
|
||||
import { playMusic as handlePlayMusic } from './playList'
|
||||
import { existsFile, moveFile, privateStorageDirectoryPath, temporaryDirectoryPath } from '@/utils/fs'
|
||||
import { toast } from '@/utils/tools'
|
||||
// import { PlayerMusicInfo } from '@/store/modules/player/playInfo'
|
||||
|
||||
|
||||
@ -173,6 +175,23 @@ export const updateNowPlayingTitles = async(duration: number, title: string, art
|
||||
|
||||
export const resetPlay = async() => Promise.all([setPause(), setCurrentTime(0)])
|
||||
|
||||
export const isCached = async(url: string) => TrackPlayer.isCached(url)
|
||||
export const getCacheSize = async() => TrackPlayer.getCacheSize()
|
||||
export const clearCache = async() => TrackPlayer.clearCache()
|
||||
export const migratePlayerCache = async() => {
|
||||
const newCachePath = privateStorageDirectoryPath + '/TrackPlayer'
|
||||
if (await existsFile(newCachePath)) return
|
||||
const oldCachePath = temporaryDirectoryPath + '/TrackPlayer'
|
||||
if (!await existsFile(oldCachePath)) return
|
||||
let timeout: number | null = BackgroundTimer.setTimeout(() => {
|
||||
timeout = null
|
||||
toast(global.i18n.t('player_cache_migrating'), 'long')
|
||||
}, 2_000)
|
||||
await moveFile(oldCachePath, newCachePath).finally(() => {
|
||||
if (timeout) BackgroundTimer.clearTimeout(timeout)
|
||||
})
|
||||
}
|
||||
|
||||
export const destroy = async() => {
|
||||
if (global.lx.playerStatus.isIniting || !global.lx.playerStatus.isInitialized) return
|
||||
await TrackPlayer.destroy()
|
||||
|
@ -7,6 +7,7 @@ import SubTitle from '../../components/SubTitle'
|
||||
import Button from '../../components/Button'
|
||||
import { toast, resetNotificationPermissionCheck, confirmDialog, resetIgnoringBatteryOptimizationCheck } from '@/utils/tools'
|
||||
import { getAppCacheSize, clearAppCache } from '@/utils/nativeModules/cache'
|
||||
import { getCacheSize, clearCache } from '@/plugins/player/utils'
|
||||
import { sizeFormate } from '@/utils'
|
||||
import { useI18n } from '@/lang'
|
||||
import Text from '@/components/common/Text'
|
||||
@ -21,8 +22,9 @@ export default memo(() => {
|
||||
// const clearCache = useDispatch('list', 'clearCache')
|
||||
|
||||
const handleGetAppCacheSize = () => {
|
||||
void getAppCacheSize().then(size => {
|
||||
setCacheSize(sizeFormate(size))
|
||||
void Promise.all([getAppCacheSize(), getCacheSize()]).then(([size, size2]) => {
|
||||
const count = size + size2
|
||||
setCacheSize(sizeFormate(count as number))
|
||||
})
|
||||
}
|
||||
|
||||
@ -36,6 +38,7 @@ export default memo(() => {
|
||||
setCleaning(true)
|
||||
void Promise.all([
|
||||
clearAppCache(),
|
||||
clearCache(),
|
||||
clearMusicUrl(),
|
||||
resetNotificationPermissionCheck(),
|
||||
resetIgnoringBatteryOptimizationCheck(),
|
||||
|
@ -43,7 +43,7 @@ export const readFile = async(path: string, encoding?: Encoding) => FileSystem.r
|
||||
|
||||
// export const copyFile = async(fromPath: string, toPath: string) => FileSystem.cp(fromPath, toPath)
|
||||
|
||||
// export const moveFile = async(fromPath: string, toPath: string) => FileSystem.mv(fromPath, toPath)
|
||||
export const moveFile = async(fromPath: string, toPath: string) => FileSystem.mv(fromPath, toPath)
|
||||
export const gzipFile = async(fromPath: string, toPath: string) => FileSystem.gzipFile(fromPath, toPath)
|
||||
export const unGzipFile = async(fromPath: string, toPath: string) => FileSystem.unGzipFile(fromPath, toPath)
|
||||
export const gzipString = async(data: string, encoding?: Encoding) => FileSystem.gzipString(data, encoding)
|
||||
|
Loading…
x
Reference in New Issue
Block a user