mirror of
https://github.com/johrpan/musicus_mobile.git
synced 2025-10-26 10:47:25 +01:00
mobile: Fix reconnection to playback service
This commit is contained in:
parent
437e6a3c2c
commit
7bf99ebd07
1 changed files with 32 additions and 28 deletions
|
|
@ -109,36 +109,40 @@ class Player {
|
||||||
|
|
||||||
/// Connect listeners and initialize streams.
|
/// Connect listeners and initialize streams.
|
||||||
void setup() {
|
void setup() {
|
||||||
if (_playbackServiceStateSubscription == null) {
|
if (_playbackServiceStateSubscription != null) {
|
||||||
// We will receive updated state information from the playback service,
|
_playbackServiceStateSubscription.cancel();
|
||||||
// which runs in its own isolate, through this port.
|
|
||||||
final receivePort = ReceivePort();
|
|
||||||
receivePort.asBroadcastStream(
|
|
||||||
onListen: (subscription) {
|
|
||||||
_playbackServiceStateSubscription = subscription;
|
|
||||||
},
|
|
||||||
).listen((msg) {
|
|
||||||
// If state is null, the background audio service has stopped.
|
|
||||||
if (msg == null) {
|
|
||||||
_stop();
|
|
||||||
} else {
|
|
||||||
if (msg is _StatusMessage) {
|
|
||||||
playing.add(msg.playing);
|
|
||||||
} else if (msg is _PositionMessage) {
|
|
||||||
_updatePosition(msg.positionMs);
|
|
||||||
} else if (msg is _TrackMessage) {
|
|
||||||
_updateCurrentTrack(msg.currentTrack);
|
|
||||||
_updateDuration(msg.positionMs, msg.durationMs);
|
|
||||||
} else if (msg is _PlaylistMessage) {
|
|
||||||
playlist.add(msg.playlist);
|
|
||||||
_updateCurrentTrack(msg.currentTrack);
|
|
||||||
_updateDuration(msg.positionMs, msg.durationMs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
IsolateNameServer.registerPortWithName(receivePort.sendPort, _portName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We will receive updated state information from the playback service,
|
||||||
|
// which runs in its own isolate, through this port.
|
||||||
|
final receivePort = ReceivePort();
|
||||||
|
receivePort.asBroadcastStream(
|
||||||
|
onListen: (subscription) {
|
||||||
|
_playbackServiceStateSubscription = subscription;
|
||||||
|
},
|
||||||
|
).listen((msg) {
|
||||||
|
// If state is null, the background audio service has stopped.
|
||||||
|
if (msg == null) {
|
||||||
|
_stop();
|
||||||
|
} else {
|
||||||
|
if (msg is _StatusMessage) {
|
||||||
|
playing.add(msg.playing);
|
||||||
|
} else if (msg is _PositionMessage) {
|
||||||
|
_updatePosition(msg.positionMs);
|
||||||
|
} else if (msg is _TrackMessage) {
|
||||||
|
_updateCurrentTrack(msg.currentTrack);
|
||||||
|
_updateDuration(msg.positionMs, msg.durationMs);
|
||||||
|
} else if (msg is _PlaylistMessage) {
|
||||||
|
playlist.add(msg.playlist);
|
||||||
|
_updateCurrentTrack(msg.currentTrack);
|
||||||
|
_updateDuration(msg.positionMs, msg.durationMs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
IsolateNameServer.removePortNameMapping(_portName);
|
||||||
|
IsolateNameServer.registerPortWithName(receivePort.sendPort, _portName);
|
||||||
|
|
||||||
if (AudioService.running) {
|
if (AudioService.running) {
|
||||||
active.add(true);
|
active.add(true);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue