Skip to content

Commit

Permalink
[ffi] Check if stream controllers are closed before adding events
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmercerind committed Aug 13, 2021
1 parent 17160ca commit 1051967
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions ffi/lib/src/internal/ffi.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,10 @@ final ReceivePort receiver = new ReceivePort()
players[playerId]!.playback.isSeekable =
event[3] == '1' ? true : false;
players[playerId]!.playback.isCompleted = false;
players[playerId]!
.playbackController
.add(players[playerId]!.playback);
if (!players[playerId]!.playbackController.isClosed)
players[playerId]!
.playbackController
.add(players[playerId]!.playback);
break;
}
case 'positionEvent':
Expand All @@ -216,9 +217,10 @@ final ReceivePort receiver = new ReceivePort()
Duration(milliseconds: int.parse(event[3]));
players[playerId]!.position.duration =
Duration(milliseconds: int.parse(event[4]));
players[playerId]!
.positionController
.add(players[playerId]!.position);
if (!players[playerId]!.positionController.isClosed)
players[playerId]!
.positionController
.add(players[playerId]!.position);
break;
}
case 'openEvent':
Expand Down Expand Up @@ -253,34 +255,38 @@ final ReceivePort receiver = new ReceivePort()
players[playerId]!.current.medias = medias;
players[playerId]!.current.media =
medias[players[playerId]!.current.index!];
players[playerId]!
.currentController
.add(players[playerId]!.current);
if (!players[playerId]!.currentController.isClosed)
players[playerId]!
.currentController
.add(players[playerId]!.current);
break;
}
case 'completeEvent':
{
players[playerId]!.playback.isCompleted =
event[2] == '1' ? true : false;
players[playerId]!
.playbackController
.add(players[playerId]!.playback);
if (!players[playerId]!.playbackController.isClosed)
players[playerId]!
.playbackController
.add(players[playerId]!.playback);
break;
}
case 'volumeEvent':
{
players[playerId]!.general.volume = double.parse(event[2]);
players[playerId]!
.generalController
.add(players[playerId]!.general);
if (!players[playerId]!.generalController.isClosed)
players[playerId]!
.generalController
.add(players[playerId]!.general);
break;
}
case 'rateEvent':
{
players[playerId]!.general.rate = double.parse(event[2]);
players[playerId]!
.generalController
.add(players[playerId]!.general);
if (!players[playerId]!.generalController.isClosed)
players[playerId]!
.generalController
.add(players[playerId]!.general);
break;
}
}
Expand Down

0 comments on commit 1051967

Please sign in to comment.