Fix audioplayer

This commit is contained in:
Christian Pauly 2020-03-15 14:15:45 +01:00
parent 2f24792648
commit 348884fc7e

View File

@ -14,6 +14,8 @@ class AudioPlayer extends StatefulWidget {
final Color color; final Color color;
final MxContent content; final MxContent content;
static String currentMxc;
const AudioPlayer(this.content, {this.color = Colors.black, Key key}) const AudioPlayer(this.content, {this.color = Colors.black, Key key})
: super(key: key); : super(key: key);
@ -37,8 +39,6 @@ class _AudioPlayerState extends State<AudioPlayer> {
double currentPosition = 0; double currentPosition = 0;
double maxPosition = 0; double maxPosition = 0;
static String currentMxc;
@override @override
void dispose() { void dispose() {
if (flutterSound.audioState == t_AUDIO_STATE.IS_PLAYING) { if (flutterSound.audioState == t_AUDIO_STATE.IS_PLAYING) {
@ -63,13 +63,13 @@ class _AudioPlayerState extends State<AudioPlayer> {
} }
_playAction() async { _playAction() async {
if (currentMxc != widget.content.mxc) { if (AudioPlayer.currentMxc != widget.content.mxc) {
if (currentMxc != null) { if (AudioPlayer.currentMxc != null) {
if (flutterSound.audioState != t_AUDIO_STATE.IS_STOPPED) { if (flutterSound.audioState != t_AUDIO_STATE.IS_STOPPED) {
await flutterSound.stopPlayer(); await flutterSound.stopPlayer();
} }
currentMxc = widget.content.mxc;
} }
AudioPlayer.currentMxc = widget.content.mxc;
} }
switch (flutterSound.audioState) { switch (flutterSound.audioState) {
case t_AUDIO_STATE.IS_PLAYING: case t_AUDIO_STATE.IS_PLAYING:
@ -86,7 +86,7 @@ class _AudioPlayerState extends State<AudioPlayer> {
codec: t_CODEC.CODEC_AAC, codec: t_CODEC.CODEC_AAC,
); );
soundSubscription ??= flutterSound.onPlayerStateChanged.listen((e) { soundSubscription ??= flutterSound.onPlayerStateChanged.listen((e) {
if (currentMxc != widget.content.mxc) { if (AudioPlayer.currentMxc != widget.content.mxc) {
soundSubscription?.cancel()?.then((f) => soundSubscription = null); soundSubscription?.cancel()?.then((f) => soundSubscription = null);
this.setState(() { this.setState(() {
currentPosition = 0; currentPosition = 0;