Skip to content

Commit

Permalink
Document why src is nullable and needs to be set last.
Browse files Browse the repository at this point in the history
  • Loading branch information
ditman committed Nov 1, 2023
1 parent 87823c2 commit 1230c99
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/video_player/video_player_web/lib/src/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class VideoPlayer {
/// This method sets the required DOM attributes so videos can [play] programmatically,
/// and attaches listeners to the internal events from the [html.VideoElement]
/// to react to them / expose them through the [VideoPlayer.events] stream.
///
/// The [src] parameter is the URL of the video. It is passed in from the plugin
/// `create` method so it can be set in the VideoElement *last*. This way, all
/// the event listeners needed to integrate the videoElement with the plugin
/// are attached before any events start firing (events start to fire when the
/// `src` attribute is set).
///
/// The `src` parameter is nullable for testing purposes.
void initialize({
String? src,
}) {
Expand Down Expand Up @@ -122,6 +130,8 @@ class VideoPlayer {
_eventController.add(VideoEvent(eventType: VideoEventType.completed));
});

// The `src` of the _videoElement is the last property that is set, so all
// the listeners for the events that the plugin cares about are attached.
if (src != null) {
_videoElement.src = src;
}
Expand Down

0 comments on commit 1230c99

Please sign in to comment.