diff --git a/assets/audio/Tintin.mp3 b/assets/audio/Tintin.mp3 new file mode 100644 index 0000000..5acd948 Binary files /dev/null and b/assets/audio/Tintin.mp3 differ diff --git a/assets/audio/backgroundAudio.mp3 b/assets/audio/backgroundAudio.mp3 deleted file mode 100644 index 372c0d5..0000000 Binary files a/assets/audio/backgroundAudio.mp3 and /dev/null differ diff --git a/lib/Global/constant.dart b/lib/Global/constant.dart index f2ab643..344e8b6 100644 --- a/lib/Global/constant.dart +++ b/lib/Global/constant.dart @@ -1,5 +1,7 @@ // ignore_for_file: prefer_const_constructors +import 'package:audioplayers/audioplayers.dart'; + /// SCORE Variables calculated in function [startGame] in [GamePage] int score = 0; int topScore = 0; @@ -30,3 +32,6 @@ double barrierMovement = 0.05; /// Screen Boundary double screenEnd = -1.9; double screenStart = 3.5; +/// audio +final player = AudioPlayer(); +bool play = true; \ No newline at end of file diff --git a/lib/Global/functions.dart b/lib/Global/functions.dart index 1b739b8..e194a11 100644 --- a/lib/Global/functions.dart +++ b/lib/Global/functions.dart @@ -1,4 +1,5 @@ // ignore_for_file: prefer_const_constructors +import 'package:audioplayers/audioplayers.dart'; import 'package:flappy_bird/Resources/strings.dart'; import 'package:flutter/material.dart'; import '../Database/database.dart'; @@ -72,6 +73,17 @@ void init() { }else{ write("level", barrierMovement); } + if(read("audio") != null){ + play = read("audio"); + }else{ + write("audio", play); + } + if(play){ + player.play(AssetSource("audio/Tintin.mp3")); + }else{ + player.stop(); + } + player.setReleaseMode(ReleaseMode.loop); } void navigate(context,navigate){ diff --git a/lib/Layouts/Pages/page_settings.dart b/lib/Layouts/Pages/page_settings.dart index d5eb93d..c6c21ff 100644 --- a/lib/Layouts/Pages/page_settings.dart +++ b/lib/Layouts/Pages/page_settings.dart @@ -1,5 +1,5 @@ // ignore_for_file: prefer_const_constructors, sized_box_for_whitespace -// ignore_for_file: prefer_const_constructors, prefer_const_literals_to_create_immutables, avoid_unnecessary_containers +// ignore_for_file: prefer_const_literals_to_create_immutables, avoid_unnecessary_containers import 'package:flappy_bird/Layouts/Pages/page_start_screen.dart'; import 'package:flappy_bird/Layouts/Widgets/widget_bird_settings.dart'; import 'package:flappy_bird/Layouts/Widgets/widget_difficulty_settings.dart'; diff --git a/lib/Layouts/Widgets/widget_music_settings.dart b/lib/Layouts/Widgets/widget_music_settings.dart index 1ca06ed..4878d2a 100644 --- a/lib/Layouts/Widgets/widget_music_settings.dart +++ b/lib/Layouts/Widgets/widget_music_settings.dart @@ -29,10 +29,12 @@ class _MusicSettingsState extends State { children: [ GestureDetector(onTap: () async { write("audio", true); + await player.resume(); }, child: Icon(Icons.music_note_rounded,size: 40,)), GestureDetector(onTap: () async { write("audio", false); + await player.pause(); }, child: Icon(Icons.music_off_rounded,size: 40)), ], diff --git a/lib/Resources/strings.dart b/lib/Resources/strings.dart index c47c577..4e55549 100644 --- a/lib/Resources/strings.dart +++ b/lib/Resources/strings.dart @@ -7,6 +7,6 @@ class Str{ " controls a bird, attempting to fly between " " columns of green pipes without hitting them"; - static String image = ""; + static String image = "0"; static String bird = "assets/pics/bird.png"; } \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 0d8f84e..6da2171 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -36,6 +36,55 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.8.2" + audioplayers: + dependency: "direct main" + description: + name: audioplayers + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + audioplayers_android: + dependency: transitive + description: + name: audioplayers_android + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.1" + audioplayers_darwin: + dependency: transitive + description: + name: audioplayers_darwin + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" + audioplayers_linux: + dependency: transitive + description: + name: audioplayers_linux + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" + audioplayers_platform_interface: + dependency: transitive + description: + name: audioplayers_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.0" + audioplayers_web: + dependency: transitive + description: + name: audioplayers_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + audioplayers_windows: + dependency: transitive + description: + name: audioplayers_windows + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" boolean_selector: dependency: transitive description: @@ -714,6 +763,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.0.1" + uuid: + dependency: transitive + description: + name: uuid + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.7" vector_math: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index dadde87..2d4a757 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,6 +39,7 @@ dependencies: path_provider: ^2.0.3 smooth_star_rating: ^1.0.4+2 rating_dialog: + audioplayers: smooth_star_rating_null_safety: ^1.0.4+2 share_plus: ^4.0.10+1 share: ^2.0.4 diff --git a/test/widget_test.dart b/test/widget_test.dart index a542501..a4330a8 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -7,12 +7,10 @@ // ignore_for_file: prefer_const_constructors -import 'package:flappy_bird/Layouts/Pages/page_game.dart'; +import 'package:flappy_bird/main.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:flappy_bird/core/main.dart'; - void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame.