PlayerWidgetSmall.ets 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import { WidgetController } from '../../common/widget/WidgetController';
  2. /**
  3. * 小尺寸播放器卡片 (2x1)
  4. * 显示基本播放控制和歌曲名称
  5. */
  6. @Entry
  7. @Component
  8. struct PlayerWidgetSmall {
  9. @LocalStorageProp('isPlaying') isPlaying: boolean = false;
  10. @LocalStorageProp('songTitle') songTitle: string = '暂无播放';
  11. @LocalStorageProp('hasNext') hasNext: boolean = false;
  12. @LocalStorageProp('hasPrevious') hasPrevious: boolean = false;
  13. build() {
  14. Row() {
  15. // 播放控制按钮区域
  16. Row() {
  17. // 上一首按钮
  18. Button() {
  19. Image($r('app.media.ic_previous2'))
  20. .width(16)
  21. .height(16)
  22. .fillColor(this.hasPrevious ? '#FF007DFF' : '#66000000')
  23. }
  24. .width(32)
  25. .height(32)
  26. .backgroundColor(Color.Transparent)
  27. .enabled(this.hasPrevious)
  28. .onClick(() => {
  29. console.info('PlayerWidgetSmall: Previous button clicked');
  30. WidgetController.handlePrevSong(this);
  31. })
  32. // 播放/暂停按钮
  33. Button() {
  34. Image(this.isPlaying ? $r('app.media.hm_pause') : $r('app.media.hm_play'))
  35. .width(20)
  36. .height(20)
  37. .fillColor('#FF007DFF')
  38. }
  39. .width(36)
  40. .height(36)
  41. .backgroundColor('#1A007DFF')
  42. .borderRadius(18)
  43. .margin({ left: 8, right: 8 })
  44. .onClick(() => {
  45. // 添加调试日志
  46. console.info('PlayerWidgetSmall: Play/Pause button clicked');
  47. WidgetController.handlePlayPause(this);
  48. })
  49. // 下一首按钮
  50. Button() {
  51. Image($r('app.media.ic_next2'))
  52. .width(16)
  53. .height(16)
  54. .fillColor(this.hasNext ? '#FF007DFF' : '#66000000')
  55. }
  56. .width(32)
  57. .height(32)
  58. .backgroundColor(Color.Transparent)
  59. .enabled(this.hasNext)
  60. .onClick(() => {
  61. console.info('PlayerWidgetSmall: Next button clicked');
  62. WidgetController.handleNextSong(this);
  63. })
  64. }
  65. .justifyContent(FlexAlign.Center)
  66. .alignItems(VerticalAlign.Center)
  67. // 歌曲信息区域
  68. Column() {
  69. Text(this.songTitle)
  70. .fontSize(14)
  71. .fontColor('#E6000000')
  72. .fontWeight(FontWeight.Medium)
  73. .maxLines(1)
  74. .textOverflow({ overflow: TextOverflow.Ellipsis })
  75. .width('100%')
  76. .textAlign(TextAlign.Start)
  77. }
  78. .layoutWeight(1)
  79. .margin({ left: 12 })
  80. .alignItems(HorizontalAlign.Start)
  81. .justifyContent(FlexAlign.Center)
  82. .onClick(() => {
  83. WidgetController.handleOpenPlayer(this);
  84. })
  85. }
  86. .width('100%')
  87. .height('100%')
  88. .padding({ left: 16, right: 16, top: 8, bottom: 8 })
  89. .backgroundColor('#FFFFFF')
  90. .borderRadius(12)
  91. .justifyContent(FlexAlign.Start)
  92. .alignItems(VerticalAlign.Center)
  93. }
  94. }