forked from md-siam/package_of_the_day
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudioplayers.dart
93 lines (87 loc) · 2.74 KB
/
audioplayers.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
class MyAudioplayer extends StatefulWidget {
const MyAudioplayer({Key? key}) : super(key: key);
@override
State<MyAudioplayer> createState() => _MyAudioplayerState();
}
class _MyAudioplayerState extends State<MyAudioplayer> {
AudioCache audioCache = AudioCache(prefix: 'assets/audios/');
late AudioPlayer player;
bool isPlaying = false;
void playAudio() async {
player = await audioCache.play(
'james_bond.wav',
mode: PlayerMode.LOW_LATENCY,
);
}
void stopAudio() {
player.stop();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.deepPurple[100],
appBar: AppBar(title: const Text('Audioplayer')),
body: Center(
child: Column(
children: [
const SizedBox(height: 20),
Stack(
alignment: Alignment.topCenter,
children: [
Container(
color: Colors.transparent,
height: 360,
),
Padding(
padding: const EdgeInsets.all(10.0),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: SizedBox(
width: 300,
height: 300,
child: Image.asset(
'assets/images/audioplayer/audioplayer.jpeg'),
),
),
),
Positioned(
bottom: 0,
child: RawMaterialButton(
padding: const EdgeInsets.all(10.0),
elevation: 12.0,
onPressed: () {
setState(() {
if (isPlaying == false) {
isPlaying = true;
playAudio();
} else {
isPlaying = false;
stopAudio();
}
});
},
shape: const CircleBorder(),
fillColor: Colors.white,
child: isPlaying
? const Icon(
Icons.stop,
size: 60,
color: Colors.green,
)
: const Icon(
Icons.play_arrow,
size: 60,
color: Colors.red,
),
),
),
],
)
],
),
),
);
}
}