mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
Initial commit
This commit is contained in:
commit
17f3040645
37 changed files with 1256 additions and 0 deletions
49
lib/backend.dart
Normal file
49
lib/backend.dart
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
|
||||
class Backend extends InheritedWidget {
|
||||
static Backend of(BuildContext context) =>
|
||||
context.inheritFromWidgetOfExactType(Backend);
|
||||
|
||||
final Widget child;
|
||||
|
||||
final playerActive = BehaviorSubject.seeded(false);
|
||||
final playing = BehaviorSubject.seeded(false);
|
||||
final position = BehaviorSubject.seeded(0.0);
|
||||
|
||||
Backend({
|
||||
@required this.child,
|
||||
}) : super(child: child);
|
||||
|
||||
void startPlayer() {
|
||||
playerActive.add(true);
|
||||
}
|
||||
|
||||
void playPause() {
|
||||
playing.add(!playing.value);
|
||||
if (playing.value) {
|
||||
simulatePlay();
|
||||
}
|
||||
}
|
||||
|
||||
void seekTo(double pos) {
|
||||
position.add(pos);
|
||||
}
|
||||
|
||||
Future<void> simulatePlay() async {
|
||||
while (playing.value) {
|
||||
await Future.delayed(Duration(milliseconds: 200));
|
||||
if (position.value >= 0.99) {
|
||||
position.add(0.0);
|
||||
} else {
|
||||
position.add(position.value + 0.01);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(Backend old) =>
|
||||
playerActive != old.playerActive ||
|
||||
playing != old.playing ||
|
||||
position != old.position;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue