summaryrefslogtreecommitdiffstats
path: root/lib/data/models/mediaplayer_state.dart
blob: f880a1ee592115d01752ed127b17e5ed8a5af08a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import 'package:flutter_ics_homescreen/export.dart';
import 'package:flutter_ics_homescreen/data/data_providers/playlist_notifier.dart';

enum PlayState { stopped, playing, paused }

@immutable
class MediaPlayerState {
  final int playlistPosition;
  final PlayState playState;
  final PlaylistEntry? song;

  const MediaPlayerState(
      {required this.playlistPosition,
      required this.playState,
      required this.song});

  const MediaPlayerState.initial()
      : playlistPosition = -1,
        playState = PlayState.stopped,
        song = null;

  MediaPlayerState copyWith(
      {int? playlistPosition,
      PlayState? playState,
      PlaylistEntry? song,
      Duration? songPosition,
      Duration? songLength}) {
    return MediaPlayerState(
      playlistPosition: playlistPosition ?? this.playlistPosition,
      playState: playState ?? this.playState,
      song: song ?? this.song,
    );
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is MediaPlayerState &&
        other.playlistPosition == playlistPosition &&
        other.playState == playState &&
        other.song == song;
  }

  @override
  int get hashCode {
    return playlistPosition.hashCode ^ playState.hashCode ^ song.hashCode;
  }
}