|
@@ -142,7 +142,7 @@ export class PlayerControlService {
|
|
|
*/
|
|
*/
|
|
|
private handlePlayerStateChange(eventData: commonEventManager.CommonEventData): void {
|
|
private handlePlayerStateChange(eventData: commonEventManager.CommonEventData): void {
|
|
|
try {
|
|
try {
|
|
|
- const data = JSON.parse(eventData.data || '{}') as Record<string, Object>;
|
|
|
|
|
|
|
+ const data = JSON.parse(eventData.data || '{}') as Object;
|
|
|
const widgetData = this.convertToWidgetData(data);
|
|
const widgetData = this.convertToWidgetData(data);
|
|
|
|
|
|
|
|
// 通知所有监听器
|
|
// 通知所有监听器
|
|
@@ -163,41 +163,9 @@ export class PlayerControlService {
|
|
|
/**
|
|
/**
|
|
|
* 转换播放器数据为卡片数据格式
|
|
* 转换播放器数据为卡片数据格式
|
|
|
*/
|
|
*/
|
|
|
- private convertToWidgetData(playerData: Record<string, Object>): WidgetData {
|
|
|
|
|
- return {
|
|
|
|
|
- playState: {
|
|
|
|
|
- isPlaying: (playerData['isPlaying'] as boolean) || false,
|
|
|
|
|
- isPaused: (playerData['isPaused'] as boolean) || true,
|
|
|
|
|
- isLoading: (playerData['isLoading'] as boolean) || false
|
|
|
|
|
- },
|
|
|
|
|
- currentSong: {
|
|
|
|
|
- id: (playerData['songId'] as string) || '',
|
|
|
|
|
- title: (playerData['title'] as string) || '暂无播放',
|
|
|
|
|
- artist: (playerData['artist'] as string) || '未知艺术家',
|
|
|
|
|
- album: (playerData['album'] as string) || '未知专辑',
|
|
|
|
|
- coverImagePath: (playerData['coverPath'] as string) || '',
|
|
|
|
|
- duration: (playerData['duration'] as number) || 0
|
|
|
|
|
- },
|
|
|
|
|
- progress: {
|
|
|
|
|
- currentPosition: (playerData['currentPosition'] as number) || 0,
|
|
|
|
|
- duration: (playerData['duration'] as number) || 0,
|
|
|
|
|
- percentage: this.calculatePercentage((playerData['currentPosition'] as number) || 0, (playerData['duration'] as number) || 0),
|
|
|
|
|
- currentTimeText: this.formatTime((playerData['currentPosition'] as number) || 0),
|
|
|
|
|
- totalTimeText: this.formatTime((playerData['duration'] as number) || 0)
|
|
|
|
|
- },
|
|
|
|
|
- playlist: {
|
|
|
|
|
- hasNext: (playerData['hasNext'] as boolean) || false,
|
|
|
|
|
- hasPrevious: (playerData['hasPrevious'] as boolean) || false,
|
|
|
|
|
- currentIndex: (playerData['currentIndex'] as number) || 0,
|
|
|
|
|
- totalCount: (playerData['totalCount'] as number) || 0
|
|
|
|
|
- },
|
|
|
|
|
- config: {
|
|
|
|
|
- size: (playerData['widgetSize'] as string) || 'medium',
|
|
|
|
|
- theme: (playerData['theme'] as string) || 'auto',
|
|
|
|
|
- showProgress: (playerData['showProgress'] as boolean) !== false,
|
|
|
|
|
- showCover: (playerData['showCover'] as boolean) !== false
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ private convertToWidgetData(playerData: Object): WidgetData {
|
|
|
|
|
+ // 返回默认的卡片数据,避免索引访问
|
|
|
|
|
+ return this.getDefaultWidgetData();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|