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 'Globals.dart';
|
||||
import 'ListenHandler.dart';
|
||||
|
||||
class Listen extends StatelessWidget {
|
||||
const Listen({super.key});
|
||||
|
||||
@@ -29,9 +26,13 @@ class _PlayControlsState extends State<PlayControls>
|
||||
|
||||
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
|
||||
initState() {
|
||||
@@ -39,20 +40,20 @@ class _PlayControlsState extends State<PlayControls>
|
||||
|
||||
print("Listen init");
|
||||
|
||||
_listenHandler.playbackState.listen((PlaybackState event) {
|
||||
if (isPlaying == event.playing) {
|
||||
print("State unchanged, skipping setState()");
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
isPlaying = event.playing;
|
||||
print("Updated playing state to $isPlaying");
|
||||
});
|
||||
});
|
||||
//_listenHandler.playbackState.listen((PlaybackState event) {
|
||||
// if (isPlaying == event.playing) {
|
||||
// print("State unchanged, skipping setState()");
|
||||
// return;
|
||||
// }
|
||||
// setState(() {
|
||||
// isPlaying = event.playing;
|
||||
// print("Updated playing state to $isPlaying");
|
||||
// });
|
||||
//});
|
||||
|
||||
//player = AudioPlayer();
|
||||
player = AudioPlayer();
|
||||
|
||||
//player.setReleaseMode(ReleaseMode.release);
|
||||
player.setReleaseMode(ReleaseMode.release);
|
||||
|
||||
//player
|
||||
// .setSourceUrl("https://generic.ything.app/music/separation-185196.mp3");
|
||||
@@ -66,7 +67,7 @@ class _PlayControlsState extends State<PlayControls>
|
||||
|
||||
//player.dispose();
|
||||
|
||||
_listenHandler.stop();
|
||||
//_listenHandler.stop();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -76,27 +77,28 @@ class _PlayControlsState extends State<PlayControls>
|
||||
print("Running build - Listen");
|
||||
|
||||
if (isPlaying) {
|
||||
player.play(_radioSource, mode: PlayerMode.mediaPlayer);
|
||||
//player.resume();
|
||||
_listenHandler.play();
|
||||
_listenHandler.playbackState.add(PlaybackState(
|
||||
controls: [
|
||||
MediaControl.stop,
|
||||
MediaControl.pause,
|
||||
],
|
||||
systemActions: {
|
||||
MediaAction.stop,
|
||||
MediaAction.pause,
|
||||
},
|
||||
playing: true,
|
||||
));
|
||||
//_listenHandler.play();
|
||||
//_listenHandler.playbackState.add(PlaybackState(
|
||||
// controls: [
|
||||
// MediaControl.stop,
|
||||
// MediaControl.pause,
|
||||
// ],
|
||||
// systemActions: {
|
||||
// MediaAction.stop,
|
||||
// MediaAction.pause,
|
||||
// },
|
||||
// playing: true,
|
||||
//));
|
||||
} else {
|
||||
//player.stop();
|
||||
_listenHandler.stop();
|
||||
_listenHandler.playbackState.add(PlaybackState(
|
||||
controls: [],
|
||||
systemActions: {},
|
||||
playing: false,
|
||||
));
|
||||
player.stop();
|
||||
//_listenHandler.stop();
|
||||
//_listenHandler.playbackState.add(PlaybackState(
|
||||
// controls: [],
|
||||
// systemActions: {},
|
||||
// playing: false,
|
||||
//));
|
||||
}
|
||||
return ClipOval(
|
||||
child: Material(
|
||||
|
||||
Reference in New Issue
Block a user