|
|
@ -3,9 +3,19 @@ import 'package:flutter/Material.dart';
|
|
|
|
import 'package:flutter_animated_play_button/flutter_animated_play_button.dart';
|
|
|
|
import 'package:flutter_animated_play_button/flutter_animated_play_button.dart';
|
|
|
|
import 'package:ionicons/ionicons.dart';
|
|
|
|
import 'package:ionicons/ionicons.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import '../model/Music.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class PlayButtonComponent extends StatefulWidget {
|
|
|
|
class PlayButtonComponent extends StatefulWidget {
|
|
|
|
final String? urlPreview;
|
|
|
|
final Music music;
|
|
|
|
const PlayButtonComponent({Key? key, required this.urlPreview})
|
|
|
|
final Function callback;
|
|
|
|
|
|
|
|
final int index;
|
|
|
|
|
|
|
|
bool playing;
|
|
|
|
|
|
|
|
PlayButtonComponent(
|
|
|
|
|
|
|
|
{Key? key,
|
|
|
|
|
|
|
|
required this.music,
|
|
|
|
|
|
|
|
required this.callback,
|
|
|
|
|
|
|
|
required this.playing,
|
|
|
|
|
|
|
|
required this.index})
|
|
|
|
: super(key: key);
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
@ -13,13 +23,12 @@ class PlayButtonComponent extends StatefulWidget {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _PlayButtonComponentState extends State<PlayButtonComponent> {
|
|
|
|
class _PlayButtonComponentState extends State<PlayButtonComponent> {
|
|
|
|
bool isPlaying = true;
|
|
|
|
|
|
|
|
final player = AudioPlayer();
|
|
|
|
final player = AudioPlayer();
|
|
|
|
void switchStatePlaying() {
|
|
|
|
void switchStatePlaying() {
|
|
|
|
setState(() {
|
|
|
|
setState(() {
|
|
|
|
isPlaying = !isPlaying;
|
|
|
|
widget.playing = !widget.playing;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
stopSong();
|
|
|
|
widget.music.stopSong();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
@ -32,12 +41,14 @@ class _PlayButtonComponentState extends State<PlayButtonComponent> {
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
if (!isPlaying) {
|
|
|
|
if (widget.playing) {
|
|
|
|
playSong();
|
|
|
|
widget.music.playSong();
|
|
|
|
} else {}
|
|
|
|
} else {}
|
|
|
|
return isPlaying
|
|
|
|
return !widget.playing
|
|
|
|
? GestureDetector(
|
|
|
|
? GestureDetector(
|
|
|
|
onTap: switchStatePlaying,
|
|
|
|
onTap: () {
|
|
|
|
|
|
|
|
widget.callback(widget.index);
|
|
|
|
|
|
|
|
},
|
|
|
|
child: Container(
|
|
|
|
child: Container(
|
|
|
|
width: 30,
|
|
|
|
width: 30,
|
|
|
|
height: 30,
|
|
|
|
height: 30,
|
|
|
@ -59,14 +70,4 @@ class _PlayButtonComponentState extends State<PlayButtonComponent> {
|
|
|
|
),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> playSong() async {
|
|
|
|
|
|
|
|
if (widget.urlPreview != null) {
|
|
|
|
|
|
|
|
await player.play(UrlSource(widget.urlPreview ?? ""));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> stopSong() async {
|
|
|
|
|
|
|
|
await player.stop();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|