feat: play audio on entering level and pause button

This commit is contained in:
Orangerot 2024-12-23 03:18:39 +01:00
parent d397b62b5b
commit 1415f91fa5
6 changed files with 219 additions and 14 deletions

View file

@ -1,12 +1,49 @@
import 'package:flutter/material.dart'; import 'dart:io';
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
class Level extends StatefulWidget {
const Level({super.key, required this.stepmaniaFolderPath});
final String stepmaniaFolderPath;
@override
State<Level> createState() => _LevelState();
}
class _LevelState extends State<Level> {
final _player = AudioPlayer();
bool _isPlaying = true;
class Level extends StatelessWidget {
const Level({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String audioPath = Directory(widget.stepmaniaFolderPath)
.listSync()
.firstWhere((entity) => entity.path.endsWith('.ogg'),
orElse: () => File(''))
.path;
_player.play(DeviceFileSource(audioPath));
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
leading: Icon(Icons.pause), leading: IconButton(
icon: Icon(_isPlaying ? Icons.pause : Icons.play_arrow),
onPressed: () => {
if (_isPlaying)
{
_player.pause(),
setState(() {
_isPlaying = false;
})
}
else
{
_player.resume(),
setState(() {
_isPlaying = true;
})
},
},
),
title: Text('Level 1'), title: Text('Level 1'),
actions: [ actions: [
IconButton( IconButton(
@ -15,10 +52,18 @@ class Level extends StatelessWidget {
], ],
), ),
body: Stack(children: [ body: Stack(children: [
Arrow( position: -100.0,), Arrow(
Arrow( position: 00.0,), position: -100.0,
Arrow( position: 100.0,), ),
Arrow( position: 200.0,), Arrow(
position: 00.0,
),
Arrow(
position: 100.0,
),
Arrow(
position: 200.0,
),
Positioned( Positioned(
top: 50, top: 50,
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
@ -43,6 +88,12 @@ class Level extends StatelessWidget {
), ),
])); ]));
} }
@override
void dispose() {
_player.dispose();
super.dispose();
}
} }
class Arrow extends StatelessWidget { class Arrow extends StatelessWidget {

View file

@ -81,12 +81,13 @@ class _LevelSelectionState extends State<LevelSelection> {
separatorBuilder: (BuildContext context, int index) => separatorBuilder: (BuildContext context, int index) =>
const Divider(), const Divider(),
itemBuilder: (context, index) { itemBuilder: (context, index) {
String thumbnailPath = String thumbnailPath = Directory(
Directory(stepmaniaCoursesFolders[index].path) stepmaniaCoursesFolders[index].path)
.listSync() .listSync()
.firstWhere((file) => file.path.toLowerCase().endsWith('banner.png'), .firstWhere(
(file) => file.path.toLowerCase().endsWith('banner.png'),
orElse: () => File('')) orElse: () => File(''))
.path; .path;
return ListTile( return ListTile(
leading: Image.file(File(thumbnailPath)), leading: Image.file(File(thumbnailPath)),
trailing: Icon(Icons.play_arrow), trailing: Icon(Icons.play_arrow),
@ -96,7 +97,10 @@ class _LevelSelectionState extends State<LevelSelection> {
onTap: () => Navigator.push( onTap: () => Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (BuildContext context) => Level())), builder: (BuildContext context) => Level(
stepmaniaFolderPath:
stepmaniaCoursesFolders[index].path,
))),
); );
}, },
); );

View file

@ -6,6 +6,10 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <audioplayers_linux/audioplayers_linux_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) audioplayers_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "AudioplayersLinuxPlugin");
audioplayers_linux_plugin_register_with_registrar(audioplayers_linux_registrar);
} }

View file

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
audioplayers_linux
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST

View file

@ -9,6 +9,62 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "2.11.0" version: "2.11.0"
audioplayers:
dependency: "direct main"
description:
name: audioplayers
sha256: c346ba5a39dc208f1bab55fc239855f573d69b0e832402114bf0b793622adc4d
url: "https://pub.dev"
source: hosted
version: "6.1.0"
audioplayers_android:
dependency: transitive
description:
name: audioplayers_android
sha256: de576b890befe27175c2f511ba8b742bec83765fa97c3ce4282bba46212f58e4
url: "https://pub.dev"
source: hosted
version: "5.0.0"
audioplayers_darwin:
dependency: transitive
description:
name: audioplayers_darwin
sha256: e507887f3ff18d8e5a10a668d7bedc28206b12e10b98347797257c6ae1019c3b
url: "https://pub.dev"
source: hosted
version: "6.0.0"
audioplayers_linux:
dependency: transitive
description:
name: audioplayers_linux
sha256: "3d3d244c90436115417f170426ce768856d8fe4dfc5ed66a049d2890acfa82f9"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
audioplayers_platform_interface:
dependency: transitive
description:
name: audioplayers_platform_interface
sha256: "6834dd48dfb7bc6c2404998ebdd161f79cd3774a7e6779e1348d54a3bfdcfaa5"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
audioplayers_web:
dependency: transitive
description:
name: audioplayers_web
sha256: "3609bdf0e05e66a3d9750ee40b1e37f2a622c4edb796cc600b53a90a30a2ace4"
url: "https://pub.dev"
source: hosted
version: "5.0.1"
audioplayers_windows:
dependency: transitive
description:
name: audioplayers_windows
sha256: "8605762dddba992138d476f6a0c3afd9df30ac5b96039929063eceed416795c2"
url: "https://pub.dev"
source: hosted
version: "4.0.0"
boolean_selector: boolean_selector:
dependency: transitive dependency: transitive
description: description:
@ -49,6 +105,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.3.4+2" version: "0.3.4+2"
crypto:
dependency: transitive
description:
name: crypto
sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855"
url: "https://pub.dev"
source: hosted
version: "3.0.6"
cupertino_icons: cupertino_icons:
dependency: "direct main" dependency: "direct main"
description: description:
@ -89,6 +153,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "8.1.6" version: "8.1.6"
fixnum:
dependency: transitive
description:
name: fixnum
sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be
url: "https://pub.dev"
source: hosted
version: "1.1.1"
flutter: flutter:
dependency: "direct main" dependency: "direct main"
description: flutter description: flutter
@ -120,6 +192,22 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
http:
dependency: transitive
description:
name: http
sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010
url: "https://pub.dev"
source: hosted
version: "1.2.2"
http_parser:
dependency: transitive
description:
name: http_parser
sha256: "76d306a1c3afb33fe82e2bbacad62a61f409b5634c915fceb0d799de1a913360"
url: "https://pub.dev"
source: hosted
version: "4.1.1"
leak_tracker: leak_tracker:
dependency: transitive dependency: transitive
description: description:
@ -184,6 +272,30 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.9.0" version: "1.9.0"
path_provider:
dependency: transitive
description:
name: path_provider
sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd"
url: "https://pub.dev"
source: hosted
version: "2.1.5"
path_provider_android:
dependency: transitive
description:
name: path_provider_android
sha256: "4adf4fd5423ec60a29506c76581bc05854c55e3a0b72d35bb28d661c9686edf2"
url: "https://pub.dev"
source: hosted
version: "2.2.15"
path_provider_foundation:
dependency: transitive
description:
name: path_provider_foundation
sha256: "4843174df4d288f5e29185bd6e72a6fbdf5a4a4602717eed565497429f179942"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
path_provider_linux: path_provider_linux:
dependency: transitive dependency: transitive
description: description:
@ -293,6 +405,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.10.0" version: "1.10.0"
sprintf:
dependency: transitive
description:
name: sprintf
sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23"
url: "https://pub.dev"
source: hosted
version: "7.0.0"
stack_trace: stack_trace:
dependency: transitive dependency: transitive
description: description:
@ -317,6 +437,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.3.0" version: "1.3.0"
synchronized:
dependency: transitive
description:
name: synchronized
sha256: "69fe30f3a8b04a0be0c15ae6490fc859a78ef4c43ae2dd5e8a623d45bfcf9225"
url: "https://pub.dev"
source: hosted
version: "3.3.0+3"
term_glyph: term_glyph:
dependency: transitive dependency: transitive
description: description:
@ -333,6 +461,22 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "0.7.3" version: "0.7.3"
typed_data:
dependency: transitive
description:
name: typed_data
sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006
url: "https://pub.dev"
source: hosted
version: "1.4.0"
uuid:
dependency: transitive
description:
name: uuid
sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff
url: "https://pub.dev"
source: hosted
version: "4.5.1"
vector_math: vector_math:
dependency: transitive dependency: transitive
description: description:

View file

@ -13,6 +13,7 @@ dependencies:
cupertino_icons: ^1.0.8 cupertino_icons: ^1.0.8
shared_preferences: ^2.3.4 shared_preferences: ^2.3.4
file_picker: ^8.1.6 file_picker: ^8.1.6
audioplayers: ^6.1.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: