| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- /**
- * 小尺寸播放器卡片 (1x2)
- * 只显示播放控制按钮:上一首、播放/暂停、下一首
- * 需求: 5.1, 1.4, 1.5
- */
- @Entry
- @Component
- struct PlayerWidgetSmall {
- // 卡片数据属性 - 使用LocalStorageProp与FormExtensionAbility通信
- @LocalStorageProp('formId') formId: string = '202501';
- @LocalStorageProp('isPlaying') isPlaying: boolean = false;
- @LocalStorageProp('songTitle') songTitle: string = 'Dream It Possible';
- @LocalStorageProp('songArtist') songArtist: string = 'Delacey';
- @LocalStorageProp('coverImage') coverImage: string = '';
- @LocalStorageProp('hasNext') hasNext: boolean = false;
- @LocalStorageProp('hasPrevious') hasPrevious: boolean = false;
- @LocalStorageProp('isLoading') isLoading: boolean = false;
- @LocalStorageProp('imageColorHex') imageColorHex: string = '2A2A2A';
- @LocalStorageProp('imgName') imgName: string = ''; // 图片文件名,用于memory://协议
- /**
- * 获取专辑封面
- */
- private getCoverImage(): Resource | string {
- console.info(`Heanup PlayerWidgetSquare: getCoverImage called, coverImage='${this.coverImage}', imgName='${this.imgName}'`);
- // 优先使用通过formImages传递的本地图片(支持网络图片下载后的显示)
- if (this.imgName && this.imgName.trim() !== '') {
- const memoryUrl = 'memory://' + this.imgName;
- console.info(`Heanup PlayerWidgetSquare: Using memory image: ${memoryUrl}`);
- return memoryUrl;
- }
- // 如果有coverImage且不是网络URL,使用本地路径
- if (this.coverImage && this.coverImage.trim() !== '' && !this.isNetworkUrl(this.coverImage)) {
- console.info(`Heanup PlayerWidgetSquare: Using local cover image: ${this.coverImage}`);
- return this.coverImage;
- }
- // 默认使用内置图片
- console.info(`Heanup PlayerWidgetSquare: Using default cover image`);
- return $r('app.media.ic_avatar4'); // 使用默认专辑封面
- }
- /**
- * 检查是否为网络URL
- */
- private isNetworkUrl(url: string): boolean {
- return url.startsWith('http://') || url.startsWith('https://');
- }
- build() {
- // 简洁的播放控制条
- Row() {
- // 上一首按钮
- Button() {
- Image($r('app.media.hm_previous'))
- .width(20)
- .height(20)
- .fillColor('#E5FFFFFF')
- }
- .width(36)
- .height(36)
- .backgroundColor(Color.Transparent)
- .opacity(this.hasPrevious ? 1.0 : 0.5)
- .onClick(() => {
- console.info(`Heanup PlayerWidgetSmall: Previous button clicked`);
- if (!this.isLoading && this.hasPrevious) {
- postCardAction(this, {
- 'action': 'call',
- 'abilityName': 'EntryAbility',
- 'params': {
- 'formId': this.formId,
- 'method': 'prevSong'
- }
- });
- }
- })
- // 播放/暂停按钮
- Button() {
- SymbolGlyph(this.isPlaying ? $r('sys.symbol.pause_round_triangle_fill') : $r('sys.symbol.play_round_triangle_fill'))
- .fontSize(28)
- .symbolEffect(new ReplaceSymbolEffect(EffectScope.WHOLE), true)
- .fontColor(['#E5FFFFFF'])
- }
- .width(44)
- .height(44)
- .backgroundColor(Color.Transparent)
- .margin({ left: 8, right: 8 })
- .onClick(() => {
- console.info('Heanup PlayerWidgetSmall: Play/Pause button clicked');
- if (!this.isLoading) {
- postCardAction(this, {
- 'action': 'call',
- 'abilityName': 'EntryAbility',
- 'params': {
- 'formId': this.formId,
- 'method': 'playPause',
- 'widgetIsPlaying': this.isPlaying // 传递卡片当前显示的播放状态
- }
- });
- }
- })
- // 下一首按钮
- Button() {
- Image($r('app.media.hm_next'))
- .width(20)
- .height(20)
- .fillColor('#E5FFFFFF')
- }
- .width(36)
- .height(36)
- .backgroundColor(Color.Transparent)
- .opacity(this.hasNext ? 1.0 : 0.5)
- .onClick(() => {
- console.info(`Heanup PlayerWidgetSmall: Next button clicked`);
- if (!this.isLoading && this.hasNext) {
- postCardAction(this, {
- 'action': 'call',
- 'abilityName': 'EntryAbility',
- 'params': {
- 'formId': this.formId,
- 'method': 'nextSong'
- }
- });
- }
- })
- }
- .width('100%')
- .height('100%')
- .justifyContent(FlexAlign.Center)
- .alignItems(VerticalAlign.Center)
- // .backgroundColor('#FF2A2A2A')
- .borderRadius(8)
- .padding(8)
- .backgroundImage(this.getCoverImage())
- .backgroundBlurStyle(BlurStyle.BACKGROUND_ULTRA_THICK)
- .backgroundImageSize(ImageSize.Cover)
- .onClick(() => {
- console.info('Heanup PlayerWidgetSmall: Container clicked, jumping to main app');
- postCardAction(this, {
- 'action': 'router',
- 'abilityName': 'EntryAbility'
- });
- })
- }
- }
|