Compare commits
2 Commits
3c02e2dc82
...
1fec1bb2f6
| Author | SHA1 | Date | |
|---|---|---|---|
| 1fec1bb2f6 | |||
| 49c5360680 |
38
src/music.js
38
src/music.js
@@ -242,12 +242,25 @@ export default class MusicList {
|
|||||||
this.ul.appendChild(ListItem({
|
this.ul.appendChild(ListItem({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
classList: item.arrayBuffer ? ['cache'] : [],
|
classList: item.arrayBuffer ? ['cache'] : [],
|
||||||
|
style: {
|
||||||
|
display: 'flex',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'space-between',
|
||||||
|
gap: '.25rem',
|
||||||
|
maxWidth: '100%',
|
||||||
|
},
|
||||||
children: [
|
children: [
|
||||||
...(item.picture ? [Img({
|
...(item.picture ? [Img({
|
||||||
src: item.picture,
|
src: item.picture,
|
||||||
style: { width: '2em', height: '2em', borderRadius: '.25em' }
|
style: { width: '2em', height: '2em', borderRadius: '.25em' }
|
||||||
})] : []),
|
})] : []),
|
||||||
Span({
|
Span({
|
||||||
|
style: {
|
||||||
|
flex: 1,
|
||||||
|
textOverflow: 'ellipsis',
|
||||||
|
whiteSpace: 'nowrap',
|
||||||
|
overflowX: 'hidden',
|
||||||
|
},
|
||||||
title: `${item.name} - ${bytesToSize(item.size)} - ${item.type}`,
|
title: `${item.name} - ${bytesToSize(item.size)} - ${item.type}`,
|
||||||
textContent: `${item.name} - ${bytesToSize(item.size)}`,
|
textContent: `${item.name} - ${bytesToSize(item.size)}`,
|
||||||
onclick: event => {
|
onclick: event => {
|
||||||
@@ -349,27 +362,6 @@ export default class MusicList {
|
|||||||
} else {
|
} else {
|
||||||
this.标题.textContent = item.name // 替换标题
|
this.标题.textContent = item.name // 替换标题
|
||||||
this.封面.src = item.picture // 替换封面图像
|
this.封面.src = item.picture // 替换封面图像
|
||||||
|
|
||||||
//// item.picture 是一个base64编码的图片, 获取图片的宽高和格式
|
|
||||||
//const [width, height, format] = (() => {
|
|
||||||
// const [, base64] = item.picture.split(',')
|
|
||||||
// const binary = atob(base64)
|
|
||||||
// const bytes = new Uint8Array(binary.length)
|
|
||||||
// for (let i = 0; i < binary.length; i++) {
|
|
||||||
// bytes[i] = binary.charCodeAt(i)
|
|
||||||
// }
|
|
||||||
// const blob = new Blob([bytes.buffer], { type: item.type })
|
|
||||||
// const url = URL.createObjectURL(blob)
|
|
||||||
// const img = new Image()
|
|
||||||
// img.src = url
|
|
||||||
// return new Promise(resolve => {
|
|
||||||
// img.onload = () => {
|
|
||||||
// resolve([img.width, img.height, img.src.split('.').pop()])
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
//})
|
|
||||||
//console.log('封面信息:', width, height, format)
|
|
||||||
|
|
||||||
// 替换浏览器媒体信息(使系统通知栏显示歌曲信息)
|
// 替换浏览器媒体信息(使系统通知栏显示歌曲信息)
|
||||||
if ('mediaSession' in navigator) {
|
if ('mediaSession' in navigator) {
|
||||||
navigator.mediaSession.metadata = new MediaMetadata({
|
navigator.mediaSession.metadata = new MediaMetadata({
|
||||||
@@ -377,9 +369,9 @@ export default class MusicList {
|
|||||||
artist: '艺术家名',
|
artist: '艺术家名',
|
||||||
album: '专辑名',
|
album: '专辑名',
|
||||||
artwork: [
|
artwork: [
|
||||||
{ src: item.picture, sizes: '96x96', type: 'image/png' },
|
{ src: item.picture, sizes: '96x96', type: 'image/jpeg' },
|
||||||
]
|
]
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
// 本地缓存直接播放
|
// 本地缓存直接播放
|
||||||
this.audio.src = URL.createObjectURL(new Blob([item.arrayBuffer], { type: item.type }))
|
this.audio.src = URL.createObjectURL(new Blob([item.arrayBuffer], { type: item.type }))
|
||||||
|
|||||||
Reference in New Issue
Block a user