now works with audio service on android
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
import 'package:audioplayers/audioplayers.dart';
|
import 'package:audio_service/audio_service.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});
|
||||||
|
|
||||||
@@ -26,13 +29,7 @@ class _PlayControlsState extends State<PlayControls>
|
|||||||
|
|
||||||
bool isPlaying = false;
|
bool isPlaying = false;
|
||||||
|
|
||||||
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() {
|
||||||
@@ -40,34 +37,23 @@ 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.setReleaseMode(ReleaseMode.release);
|
|
||||||
|
|
||||||
//player
|
|
||||||
// .setSourceUrl("https://generic.ything.app/music/separation-185196.mp3");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
|
|
||||||
//player.stop();
|
_listenHandler.stop();
|
||||||
|
|
||||||
//player.dispose();
|
|
||||||
|
|
||||||
//_listenHandler.stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -77,28 +63,25 @@ class _PlayControlsState extends State<PlayControls>
|
|||||||
print("Running build - Listen");
|
print("Running build - Listen");
|
||||||
|
|
||||||
if (isPlaying) {
|
if (isPlaying) {
|
||||||
player.play(_radioSource, mode: PlayerMode.mediaPlayer);
|
_listenHandler.play();
|
||||||
//player.resume();
|
_listenHandler.playbackState.add(PlaybackState(
|
||||||
//_listenHandler.play();
|
controls: [
|
||||||
//_listenHandler.playbackState.add(PlaybackState(
|
MediaControl.stop,
|
||||||
// controls: [
|
MediaControl.pause,
|
||||||
// MediaControl.stop,
|
],
|
||||||
// MediaControl.pause,
|
systemActions: {
|
||||||
// ],
|
MediaAction.stop,
|
||||||
// systemActions: {
|
MediaAction.pause,
|
||||||
// MediaAction.stop,
|
},
|
||||||
// MediaAction.pause,
|
playing: true,
|
||||||
// },
|
));
|
||||||
// playing: true,
|
|
||||||
//));
|
|
||||||
} else {
|
} else {
|
||||||
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(
|
||||||
|
|||||||
@@ -5,13 +5,12 @@ import 'package:ything_radio/Globals.dart';
|
|||||||
class ListenHandler extends BaseAudioHandler {
|
class ListenHandler extends BaseAudioHandler {
|
||||||
final _player = AudioPlayer();
|
final _player = AudioPlayer();
|
||||||
|
|
||||||
|
final UrlSource _radioSource = UrlSource(
|
||||||
|
"https://generic.ything.app/music/separation-185196.mp3",
|
||||||
|
mimeType: "audio/mpeg");
|
||||||
|
|
||||||
setup_player() {
|
setup_player() {
|
||||||
_player.setReleaseMode(ReleaseMode.release);
|
_player.setReleaseMode(ReleaseMode.release);
|
||||||
|
|
||||||
_player.setSourceUrl(
|
|
||||||
"https://generic.ything.app/music/separation-185196.mp3",
|
|
||||||
mimeType: "audio/mpeg",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ListenHandler() {
|
ListenHandler() {
|
||||||
@@ -21,7 +20,7 @@ class ListenHandler extends BaseAudioHandler {
|
|||||||
@override
|
@override
|
||||||
Future<void> play() async {
|
Future<void> play() async {
|
||||||
if (await startAudioSession()) {
|
if (await startAudioSession()) {
|
||||||
_player.resume();
|
_player.play(_radioSource, mode: PlayerMode.mediaPlayer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user