|
|
@@ -91,7 +91,7 @@ export default class EntryFormAbility extends FormExtensionAbility {
|
|
|
});
|
|
|
|
|
|
// 返回初始数据作为临时显示
|
|
|
- const adaptedData = this.buildWidgetData();
|
|
|
+ const adaptedData = this.unifiedPlayerService.getWidgetFormData();
|
|
|
console.info(`[EntryFormAbility] onAddForm returning data for ${formId}:`, JSON.stringify(adaptedData));
|
|
|
|
|
|
return formBindingData.createFormBindingData(adaptedData);
|
|
|
@@ -173,102 +173,6 @@ export default class EntryFormAbility extends FormExtensionAbility {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private buildWidgetData(): FormWidgetData {
|
|
|
- // 构建与UnifiedPlayerService一致的数据结构
|
|
|
- try {
|
|
|
- const currentSong = this.unifiedPlayerService.getCurrentSong();
|
|
|
- const currentState = this.unifiedPlayerService.getCurrentState();
|
|
|
-
|
|
|
- if (!currentSong) {
|
|
|
- const defaultData: FormWidgetData = {
|
|
|
- id: '',
|
|
|
- name: '未知歌曲',
|
|
|
- artist: '未知艺术家',
|
|
|
- album: '未知专辑',
|
|
|
- pixelMapPath: '',
|
|
|
- duration: 0,
|
|
|
- filePath: '',
|
|
|
- imgName: '',
|
|
|
- imageColorHex: '2A2A2A',
|
|
|
- isPlaying: false,
|
|
|
- isPaused: true,
|
|
|
- isLoading: false,
|
|
|
- hasNext: false,
|
|
|
- hasPrevious: false
|
|
|
- };
|
|
|
- return defaultData;
|
|
|
- }
|
|
|
-
|
|
|
- // 返回平铺数据结构,与widget组件期望的格式一致
|
|
|
- const widgetData: FormWidgetData = {
|
|
|
- // VideoItem数据
|
|
|
- id: currentSong.id || '',
|
|
|
- name: currentSong.name || '',
|
|
|
- artist: currentSong.artist || '',
|
|
|
- album: currentSong.album || '',
|
|
|
- pixelMapPath: currentSong.pixelMapPath || '',
|
|
|
- duration: typeof currentSong.duration === 'string' ? parseInt(currentSong.duration || '0') : (currentSong.duration || 0),
|
|
|
- filePath: currentSong.filePath || '',
|
|
|
- imgName: '',
|
|
|
- imageColorHex: '2A2A2A',
|
|
|
-
|
|
|
- // PlayerState数据平铺
|
|
|
- isPlaying: currentState.isPlaying || false,
|
|
|
- isPaused: currentState.isPaused || true,
|
|
|
- isLoading: currentState.isLoading || false,
|
|
|
- hasNext: currentState.hasNext || false,
|
|
|
- hasPrevious: currentState.hasPrevious || false,
|
|
|
- playMode: currentState.playMode || 0,
|
|
|
-
|
|
|
- // 播放列表信息
|
|
|
- currentIndex: this.unifiedPlayerService.getCurrentIndex(),
|
|
|
- totalCount: this.unifiedPlayerService.getPlaylist().length,
|
|
|
-
|
|
|
- // 时间信息
|
|
|
- currentTimeText: this.formatTimeDisplay(Math.floor((currentState.currentPosition || 0) / 1000)),
|
|
|
- totalTimeText: this.formatTimeDisplay(Math.floor((currentState.duration || 0) / 1000)),
|
|
|
- progressPercentage: this.calculateProgressPercentage(currentState.currentPosition || 0, currentState.duration || 0)
|
|
|
- };
|
|
|
- return widgetData;
|
|
|
- } catch (error) {
|
|
|
- console.error(`[EntryFormAbility] Failed to build widget data: ${error}`);
|
|
|
- const errorData: FormWidgetData = {
|
|
|
- id: '',
|
|
|
- name: 'Error',
|
|
|
- artist: 'Unknown',
|
|
|
- album: 'Unknown',
|
|
|
- pixelMapPath: '',
|
|
|
- duration: 0,
|
|
|
- filePath: '',
|
|
|
- imgName: '',
|
|
|
- imageColorHex: '2A2A2A',
|
|
|
- isPlaying: false,
|
|
|
- isPaused: true,
|
|
|
- isLoading: false,
|
|
|
- hasNext: false,
|
|
|
- hasPrevious: false
|
|
|
- };
|
|
|
- return errorData;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 格式化时间显示
|
|
|
- */
|
|
|
- private formatTimeDisplay(seconds: number): string {
|
|
|
- const mins = Math.floor(seconds / 60);
|
|
|
- const secs = Math.floor(seconds % 60);
|
|
|
- return `${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}`;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 计算播放进度百分比
|
|
|
- */
|
|
|
- private calculateProgressPercentage(current: number, total: number): number {
|
|
|
- if (total <= 0) return 0;
|
|
|
- return Math.min(100, Math.max(0, (current / total) * 100));
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* 保存 Form ID 到持久化存储
|