apparently android needs .play() first or it wont work
This commit is contained in:
@@ -1,9 +1,6 @@
|
|||||||
import 'package:audio_service/audio_service.dart';
|
import 'package:audioplayers/audioplayers.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'Globals.dart';
|
|
||||||
import 'ListenHandler.dart';
|
|
||||||
|
|
||||||
class Listen extends StatelessWidget {
|
class Listen extends StatelessWidget {
|
||||||
const Listen({super.key});
|
const Listen({super.key});
|
||||||
|
|
||||||
@@ -29,9 +26,13 @@ class _PlayControlsState extends State<PlayControls>
|
|||||||
|
|
||||||
bool isPlaying = false;
|
bool isPlaying = false;
|
||||||
|
|
||||||
//late final AudioPlayer player;
|
late final AudioPlayer player;
|
||||||
|
|
||||||
final ListenHandler _listenHandler = getListenHandlder();
|
//final ListenHandler _listenHandler = getListenHandlder();
|
||||||
|
|
||||||
|
final UrlSource _radioSource = UrlSource(
|
||||||
|
"https://generic.ything.app/music/separation-185196.mp3",
|
||||||
|
mimeType: "audio/mpeg");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
initState() {
|
initState() {
|
||||||
@@ -39,20 +40,20 @@ class _PlayControlsState extends State<PlayControls>
|
|||||||
|
|
||||||
print("Listen init");
|
print("Listen init");
|
||||||
|
|
||||||
_listenHandler.playbackState.listen((PlaybackState event) {
|
//_listenHandler.playbackState.listen((PlaybackState event) {
|
||||||
if (isPlaying == event.playing) {
|
// if (isPlaying == event.playing) {
|
||||||
print("State unchanged, skipping setState()");
|
// print("State unchanged, skipping setState()");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
setState(() {
|
// setState(() {
|
||||||
isPlaying = event.playing;
|
// isPlaying = event.playing;
|
||||||
print("Updated playing state to $isPlaying");
|
// print("Updated playing state to $isPlaying");
|
||||||
});
|
// });
|
||||||
});
|
//});
|
||||||
|
|
||||||
//player = AudioPlayer();
|
player = AudioPlayer();
|
||||||
|
|
||||||
//player.setReleaseMode(ReleaseMode.release);
|
player.setReleaseMode(ReleaseMode.release);
|
||||||
|
|
||||||
//player
|
//player
|
||||||
// .setSourceUrl("https://generic.ything.app/music/separation-185196.mp3");
|
// .setSourceUrl("https://generic.ything.app/music/separation-185196.mp3");
|
||||||
@@ -66,7 +67,7 @@ class _PlayControlsState extends State<PlayControls>
|
|||||||
|
|
||||||
//player.dispose();
|
//player.dispose();
|
||||||
|
|
||||||
_listenHandler.stop();
|
//_listenHandler.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -76,27 +77,28 @@ class _PlayControlsState extends State<PlayControls>
|
|||||||
print("Running build - Listen");
|
print("Running build - Listen");
|
||||||
|
|
||||||
if (isPlaying) {
|
if (isPlaying) {
|
||||||
|
player.play(_radioSource, mode: PlayerMode.mediaPlayer);
|
||||||
//player.resume();
|
//player.resume();
|
||||||
_listenHandler.play();
|
//_listenHandler.play();
|
||||||
_listenHandler.playbackState.add(PlaybackState(
|
//_listenHandler.playbackState.add(PlaybackState(
|
||||||
controls: [
|
// controls: [
|
||||||
MediaControl.stop,
|
// MediaControl.stop,
|
||||||
MediaControl.pause,
|
// MediaControl.pause,
|
||||||
],
|
// ],
|
||||||
systemActions: {
|
// systemActions: {
|
||||||
MediaAction.stop,
|
// MediaAction.stop,
|
||||||
MediaAction.pause,
|
// MediaAction.pause,
|
||||||
},
|
// },
|
||||||
playing: true,
|
// playing: true,
|
||||||
));
|
//));
|
||||||
} else {
|
} else {
|
||||||
//player.stop();
|
player.stop();
|
||||||
_listenHandler.stop();
|
//_listenHandler.stop();
|
||||||
_listenHandler.playbackState.add(PlaybackState(
|
//_listenHandler.playbackState.add(PlaybackState(
|
||||||
controls: [],
|
// controls: [],
|
||||||
systemActions: {},
|
// systemActions: {},
|
||||||
playing: false,
|
// playing: false,
|
||||||
));
|
//));
|
||||||
}
|
}
|
||||||
return ClipOval(
|
return ClipOval(
|
||||||
child: Material(
|
child: Material(
|
||||||
|
|||||||
Reference in New Issue
Block a user