Skip to content

Commit

Permalink
Play sound when turn finishes
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonfagan committed Oct 31, 2022
1 parent e39883d commit da28847
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/pages/timer/helpers/ticker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import 'dart:async';
import 'package:mob_app/common/log.dart';

class Ticker {
Ticker({required this.onTick});
Ticker({required this.onTick, this.onStop});

final Function() onTick;
final Function()? onStop;

late Timer _timer;
late int _secondsRemaining;
Expand All @@ -20,6 +21,7 @@ class Ticker {
debug('Seconds Remaining: $_secondsRemaining');
if (_secondsRemaining < 1) {
stop();
onStop?.call();
} else {
_secondsRemaining -= 1;
}
Expand Down
10 changes: 9 additions & 1 deletion lib/pages/timer/timer.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
import 'package:mob_app/pages/timer/helpers/ticker.dart';
import 'package:mob_app/providers/mob.dart';
Expand All @@ -18,7 +19,10 @@ class TimerPage extends StatefulWidget {
}

class _TimerPageState extends State<TimerPage> {
late final _ticker = Ticker(onTick: _update);
late final _ticker = Ticker(
onTick: _update,
onStop: _playChime,
);

@override
void initState() {
Expand All @@ -44,6 +48,10 @@ class _TimerPageState extends State<TimerPage> {
setState(() => _ticker.stop());
}

void _playChime() async {
await AudioPlayer().play(UrlSource('sounds/chime.wav'));
}

@override
Widget build(BuildContext context) {
final mob = Provider.of<MobProvider>(context);
Expand Down
215 changes: 214 additions & 1 deletion pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,62 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.9.0"
audioplayers:
dependency: "direct main"
description:
name: audioplayers
sha256: a73737eb4d025492e523ab69d13a054bc4130fc378588c78272e84e89753322e
url: "https://pub.dev"
source: hosted
version: "1.1.1"
audioplayers_android:
dependency: transitive
description:
name: audioplayers_android
sha256: c06e784e2b4d50b31a634acc6edda89584e557e756815819ee0c06c75fc4b89a
url: "https://pub.dev"
source: hosted
version: "1.1.1"
audioplayers_darwin:
dependency: transitive
description:
name: audioplayers_darwin
sha256: b8d3a3e6a0b0b9080d9ca79241b95ebf3e7d7641e88a737bfb0c23f416e017b3
url: "https://pub.dev"
source: hosted
version: "1.0.3"
audioplayers_linux:
dependency: transitive
description:
name: audioplayers_linux
sha256: "62ba684199270f548b801d5387fa72cb60d12ada78b687924e7364f6bf1c7d34"
url: "https://pub.dev"
source: hosted
version: "1.0.1"
audioplayers_platform_interface:
dependency: transitive
description:
name: audioplayers_platform_interface
sha256: "51b237362834a12d86a0adccb3b65c63923945dc572c2aaea4db0645ea1fc256"
url: "https://pub.dev"
source: hosted
version: "2.0.0"
audioplayers_web:
dependency: transitive
description:
name: audioplayers_web
sha256: "8a09d08d19470cbce5cdf73f3561d0f6d0d5c631372fb41cd959770f8d4ce607"
url: "https://pub.dev"
source: hosted
version: "2.0.1"
audioplayers_windows:
dependency: transitive
description:
name: audioplayers_windows
sha256: "5b4cff2d10bee5ce6afcd09a0a496bc1e4d5c60db432d0f4208c5d7aefcbed29"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -41,6 +97,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.17.0"
crypto:
dependency: transitive
description:
name: crypto
sha256: aa274aa7774f8964e4f4f38cc994db7b6158dd36e9187aaceaddc994b35c6c67
url: "https://pub.dev"
source: hosted
version: "3.0.2"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -57,6 +121,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
ffi:
dependency: transitive
description:
name: ffi
sha256: a38574032c5f1dd06c4aee541789906c12ccaab8ba01446e800d9c5b79c4a978
url: "https://pub.dev"
source: hosted
version: "2.0.1"
file:
dependency: transitive
description:
name: file
sha256: "1b92bec4fc2a72f59a8e15af5f52cd441e4a7860b49499d69dfa817af20e925d"
url: "https://pub.dev"
source: hosted
version: "6.1.4"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -75,6 +155,27 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
http:
dependency: transitive
description:
name: http
sha256: "6aa2946395183537c8b880962d935877325d6a09a2867c3970c05c0fed6ac482"
url: "https://pub.dev"
source: hosted
version: "0.13.5"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "2aa08ce0341cc9b354a498388e30986515406668dbcc4f7c950c3e715496693b"
url: "https://pub.dev"
source: hosted
version: "4.0.2"
js:
dependency: transitive
description:
Expand Down Expand Up @@ -131,6 +232,86 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.8.2"
path_provider:
dependency: transitive
description:
name: path_provider
sha256: "050e8e85e4b7fecdf2bb3682c1c64c4887a183720c802d323de8a5fd76d372dd"
url: "https://pub.dev"
source: hosted
version: "2.0.11"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
sha256: "4d5542667150f5b779ba411dd5dc0b674a85d1355e45bda2877e0e82f4ad08d8"
url: "https://pub.dev"
source: hosted
version: "2.0.20"
path_provider_ios:
dependency: transitive
description:
name: path_provider_ios
sha256: "03d639406f5343478352433f00d3c4394d52dac8df3d847869c5e2333e0bbce8"
url: "https://pub.dev"
source: hosted
version: "2.0.11"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
sha256: ab0987bf95bc591da42dffb38c77398fc43309f0b9b894dcc5d6f40c4b26c379
url: "https://pub.dev"
source: hosted
version: "2.1.7"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
sha256: "2a97e7fbb7ae9dcd0dfc1220a78e9ec3e71da691912e617e8715ff2a13086ae8"
url: "https://pub.dev"
source: hosted
version: "2.0.6"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
sha256: f0abc8ebd7253741f05488b4813d936b4d07c6bae3e86148a09e342ee4b08e76
url: "https://pub.dev"
source: hosted
version: "2.0.5"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
sha256: bcabbe399d4042b8ee687e17548d5d3f527255253b4a639f5f8d2094a9c2b45c
url: "https://pub.dev"
source: hosted
version: "2.1.3"
platform:
dependency: transitive
description:
name: platform
sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76"
url: "https://pub.dev"
source: hosted
version: "3.1.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: dbf0f707c78beedc9200146ad3cb0ab4d5da13c246336987be6940f026500d3a
url: "https://pub.dev"
source: hosted
version: "2.1.3"
process:
dependency: transitive
description:
name: process
sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09"
url: "https://pub.dev"
source: hosted
version: "4.2.4"
provider:
dependency: "direct main"
description:
Expand Down Expand Up @@ -192,6 +373,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.4.14"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: "26f87ade979c47a150c9eaab93ccd2bebe70a27dc0b4b29517f2904f04eb11a5"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
uuid:
dependency: transitive
description:
name: uuid
sha256: "2469694ad079893e3b434a627970c33f2fa5adc46dfe03c9617546969a9a8afc"
url: "https://pub.dev"
source: hosted
version: "3.0.6"
vector_math:
dependency: transitive
description:
Expand All @@ -200,6 +397,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.4"
win32:
dependency: transitive
description:
name: win32
sha256: "9555cd63283445e101f0df32105862fdc0b30adb9b84fd0553e9433b3e074d4c"
url: "https://pub.dev"
source: hosted
version: "3.0.1"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
sha256: "11541eedefbcaec9de35aa82650b695297ce668662bbd6e3911a7fabdbde589f"
url: "https://pub.dev"
source: hosted
version: "0.2.0+2"
sdks:
dart: ">=2.18.2 <4.0.0"
flutter: ">=1.16.0"
flutter: ">=3.0.0"
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
provider: ^6.0.4
audioplayers: ^1.1.1

dev_dependencies:
flutter_test:
Expand Down Expand Up @@ -64,6 +65,8 @@ flutter:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
assets:
- sounds/chime.wav

# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
Expand Down
Binary file added sounds/chime.wav
Binary file not shown.

0 comments on commit da28847

Please sign in to comment.