diff options
author | Orangerot <purple@orangerot.dev> | 2024-12-23 03:18:39 +0100 |
---|---|---|
committer | Orangerot <purple@orangerot.dev> | 2024-12-23 03:18:39 +0100 |
commit | 1415f91fa5f32b53f69332c7f1ef1129a3d9f454 (patch) | |
tree | b8988e9a40fe01c38806aea422945b33f1a0424f /lib/level.dart | |
parent | d397b62b5b6f6db45a2cc0ae6ca4e03ff04c54b2 (diff) |
feat: play audio on entering level and pause button
Diffstat (limited to 'lib/level.dart')
-rw-r--r-- | lib/level.dart | 65 |
1 files changed, 58 insertions, 7 deletions
diff --git a/lib/level.dart b/lib/level.dart index c92658b..e35325a 100644 --- a/lib/level.dart +++ b/lib/level.dart @@ -1,12 +1,49 @@ +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 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( 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'), actions: [ IconButton( @@ -15,10 +52,18 @@ class Level extends StatelessWidget { ], ), body: Stack(children: [ - Arrow( position: -100.0,), - Arrow( position: 00.0,), - Arrow( position: 100.0,), - Arrow( position: 200.0,), + Arrow( + position: -100.0, + ), + Arrow( + position: 00.0, + ), + Arrow( + position: 100.0, + ), + Arrow( + position: 200.0, + ), Positioned( top: 50, 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 { |