aboutsummaryrefslogtreecommitdiffstats
path: root/lib/data/data_providers/play_controller.dart
blob: 38ef3092d4540a540e1f52a191af70c6ca586579 (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
import 'package:flutter_ics_homescreen/export.dart';

enum PlaySource { none, media, radio }

class PlayController {
  final Ref ref;
  PlaySource source = PlaySource.none;

  PlayController({required this.ref});

  void setSource(PlaySource newSource) {
    source = newSource;
  }

  void play() async {
    switch (source) {
      case PlaySource.media:
        ref.read(mpdClientProvider).play();
        break;
      case PlaySource.radio:
        ref.read(radioClientProvider).start();
        break;
      default:
        break;
    }
  }

  void pause() async {
    switch (source) {
      case PlaySource.media:
        ref.read(mpdClientProvider).pause();
        break;
      case PlaySource.radio:
        ref.read(radioClientProvider).stop();
        break;
      default:
        break;
    }
  }
}