MusiPlayerViewStateHelper.ets 774 B

123456789101112131415161718192021222324252627
  1. import { stringForTime } from '../../common/util/CommUtils'
  2. import { VideoItem } from '../../viewmodel/VideoItem'
  3. export interface PlayerTimeTexts {
  4. currentTime: string
  5. totalTime: string
  6. }
  7. function normalizeMilliseconds(value: number): number {
  8. if (!Number.isFinite(value) || value < 0) {
  9. return 0
  10. }
  11. return value
  12. }
  13. export function resolvePlayerTimeTexts(positionMs: number, durationMs: number): PlayerTimeTexts {
  14. return {
  15. currentTime: stringForTime(normalizeMilliseconds(positionMs)),
  16. totalTime: stringForTime(normalizeMilliseconds(durationMs))
  17. }
  18. }
  19. export function resolvePlayerLyricContent(currentSong?: VideoItem): string {
  20. const lyricContent = currentSong?.lyricContent ?? ''
  21. return lyricContent.trim().length > 0 ? lyricContent : ''
  22. }