forked from md-siam/package_of_the_day
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjust_audio.dart
78 lines (72 loc) · 2.29 KB
/
just_audio.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import 'package:flutter/material.dart';
import 'package:audio_video_progress_bar/audio_video_progress_bar.dart';
import 'page_manager.dart';
class MyJustAudio extends StatefulWidget {
const MyJustAudio({Key? key}) : super(key: key);
@override
State<MyJustAudio> createState() => _MyJustAudioState();
}
class _MyJustAudioState extends State<MyJustAudio> {
late final PageManager _pageManager;
@override
void initState() {
super.initState();
_pageManager = PageManager();
}
@override
void dispose() {
_pageManager.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Just Audio')),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
const Spacer(),
ValueListenableBuilder<ProgressBarState>(
valueListenable: _pageManager.progressNotifier,
builder: (_, value, __) {
return ProgressBar(
progress: value.current,
buffered: value.buffered,
total: value.total,
onSeek: _pageManager.seek,
);
},
),
ValueListenableBuilder<ButtonState>(
valueListenable: _pageManager.buttonNotifier,
builder: (_, value, __) {
switch (value) {
case ButtonState.loading:
return Container(
margin: const EdgeInsets.all(8.0),
width: 32.0,
height: 32.0,
child: const CircularProgressIndicator(),
);
case ButtonState.paused:
return IconButton(
icon: const Icon(Icons.play_arrow),
iconSize: 32.0,
onPressed: _pageManager.play,
);
case ButtonState.playing:
return IconButton(
icon: const Icon(Icons.pause),
iconSize: 32.0,
onPressed: _pageManager.pause,
);
}
},
),
],
),
),
);
}
}