ahutchen commited on
Commit
3b9298b
·
1 Parent(s): 0823b09

perf: 优化专辑封面图片尺寸

Browse files

- 在 MediaSessionManager 中将专辑封面图片尺寸从 512 调整为 300
- 在 musicPicCache 中强制使用 300 尺寸,忽略传入的 size 参数
- 这些更改可以减少图片加载时间,提高应用性能

src/utils/mediaSession.js CHANGED
@@ -82,7 +82,7 @@ class MediaSessionManager {
82
  try {
83
  const { usePlayerStore } = await import('@/stores/player')
84
  const playerStore = usePlayerStore()
85
- coverUrl = await playerStore.getAlbumCover(song, 512)
86
  } catch (error) {
87
  console.warn('获取专辑封面失败:', error)
88
  }
 
82
  try {
83
  const { usePlayerStore } = await import('@/stores/player')
84
  const playerStore = usePlayerStore()
85
+ coverUrl = await playerStore.getAlbumCover(song, 300)
86
  } catch (error) {
87
  console.warn('获取专辑封面失败:', error)
88
  }
src/utils/musicPicCache.js CHANGED
@@ -14,7 +14,8 @@ const pendingRequests = new Map()
14
  export async function getCachedMusicPicUrl(source, id, size = 300, skipCache = false) {
15
  if (!source || !id) return null
16
 
17
- const sizeStr = String(size)
 
18
 
19
  // 先检查缓存(除非明确跳过)
20
  if (!skipCache) {
@@ -75,7 +76,8 @@ export async function getCachedMusicPicUrl(source, id, size = 300, skipCache = f
75
  export async function getCachedMusicPicUrlWithDelay(source, id, size = 300) {
76
  if (!source || !id) return null
77
 
78
- const sizeStr = String(size)
 
79
 
80
  // 先检查缓存
81
  const cached = urlCacheManager.getCachedUrl(source, id, sizeStr)
@@ -91,7 +93,7 @@ export async function getCachedMusicPicUrlWithDelay(source, id, size = 300) {
91
  await new Promise(resolve => setTimeout(resolve, 200))
92
  }
93
 
94
- return getCachedMusicPicUrl(source, id, size)
95
  }
96
 
97
  /**
@@ -103,7 +105,8 @@ export async function getCachedMusicPicUrlWithDelay(source, id, size = 300) {
103
  export async function preloadMusicPics(songs, size = 300, concurrency = 1) {
104
  if (!Array.isArray(songs) || songs.length === 0) return
105
 
106
- const sizeStr = String(size)
 
107
 
108
  // 过滤出需要加载的歌曲(未缓存的)
109
  const toLoad = songs.filter(song => {
@@ -117,7 +120,7 @@ export async function preloadMusicPics(songs, size = 300, concurrency = 1) {
117
  for (let i = 0; i < toLoad.length; i += concurrency) {
118
  const batch = toLoad.slice(i, i + concurrency)
119
  const promises = batch.map(song =>
120
- getCachedMusicPicUrl(song.source, song.pic_id, size).catch(error => {
121
  console.warn(`预加载 ${song.name} 图片失败:`, error)
122
  return null
123
  })
 
14
  export async function getCachedMusicPicUrl(source, id, size = 300, skipCache = false) {
15
  if (!source || !id) return null
16
 
17
+ // 强制使用 300 尺寸,不管传入什么参数
18
+ const sizeStr = '300'
19
 
20
  // 先检查缓存(除非明确跳过)
21
  if (!skipCache) {
 
76
  export async function getCachedMusicPicUrlWithDelay(source, id, size = 300) {
77
  if (!source || !id) return null
78
 
79
+ // 强制使用 300 尺寸,不管传入什么参数
80
+ const sizeStr = '300'
81
 
82
  // 先检查缓存
83
  const cached = urlCacheManager.getCachedUrl(source, id, sizeStr)
 
93
  await new Promise(resolve => setTimeout(resolve, 200))
94
  }
95
 
96
+ return getCachedMusicPicUrl(source, id, 300)
97
  }
98
 
99
  /**
 
105
  export async function preloadMusicPics(songs, size = 300, concurrency = 1) {
106
  if (!Array.isArray(songs) || songs.length === 0) return
107
 
108
+ // 强制使用 300 尺寸,不管传入什么参数
109
+ const sizeStr = '300'
110
 
111
  // 过滤出需要加载的歌曲(未缓存的)
112
  const toLoad = songs.filter(song => {
 
120
  for (let i = 0; i < toLoad.length; i += concurrency) {
121
  const batch = toLoad.slice(i, i + concurrency)
122
  const promises = batch.map(song =>
123
+ getCachedMusicPicUrl(song.source, song.pic_id, 300).catch(error => {
124
  console.warn(`预加载 ${song.name} 图片失败:`, error)
125
  return null
126
  })