[video_player_avplay] Fixed an issue where subtitles for content with pre-roll/insesrted ads in DASH could not be rendered.#1007
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the caption selection logic in video_player.dart to include start-time checks for both text and picture captions. A logic error was identified in the picture caption implementation where the greater-than operator was used instead of the less-than operator for the start time check, which would cause captions to be hidden incorrectly during their display window.
There was a problem hiding this comment.
Code Review
This pull request updates the video_player_avplay package to version 0.8.8 and modifies the _currentCaptions getter to prevent subtitle rendering when the playback position is before the caption start time. Feedback identifies critical safety issues where the new conditional checks could cause runtime crashes due to null or empty list access, and notes that similar logic in other methods remains inconsistent. Additionally, a typo was found in the changelog.
| (captions.textCaptions == <TextCaption>[TextCaption.none] || | ||
| position > captions.textCaptions![0].end) | ||
| position > captions.textCaptions![0].end || | ||
| position < captions.textCaptions![0].start) |
There was a problem hiding this comment.
The conditional check for textCaptions is unsafe and potentially incorrect for several reasons:
- Null/Empty Safety: If
captions.textCaptionsisnullor an empty list, accessing[0]will cause a runtime crash. The current checkcaptions.textCaptions == <TextCaption>[TextCaption.none]is also unreliable in Dart as it performs a reference comparison on a new list literal, which will likely evaluate tofalseeven if the contents are identical. - Logic Inconsistency: This fix only addresses
_currentCaptions. However,_getCaptionAt(line 1159) appears to have identical logic that was not updated in this PR. Since_updatePositionrelies on_getCaptionAt, the issue with subtitles being rendered outside their time range might persist during normal playback updates.
Consider using a more robust check that handles null/empty cases and ensures consistency across the file.
| (captions.textCaptions == <TextCaption>[TextCaption.none] || | |
| position > captions.textCaptions![0].end) | |
| position > captions.textCaptions![0].end || | |
| position < captions.textCaptions![0].start) | |
| (captions.textCaptions == null || | |
| captions.textCaptions!.isEmpty || | |
| captions.textCaptions![0] == TextCaption.none || | |
| position > captions.textCaptions![0].end || | |
| position < captions.textCaptions![0].start) |
| (captions.pictureCaption == PictureCaption.none || | ||
| position > captions.pictureCaption!.end) | ||
| position > captions.pictureCaption!.end || | ||
| position < captions.pictureCaption!.start) |
There was a problem hiding this comment.
This check is unsafe if captions.pictureCaption is null. Accessing .end or .start will result in a crash. Also, ensure this logic is synchronized with _getPictureCaptionAt (line 1179) for consistency.
| (captions.pictureCaption == PictureCaption.none || | |
| position > captions.pictureCaption!.end) | |
| position > captions.pictureCaption!.end || | |
| position < captions.pictureCaption!.start) | |
| (captions.pictureCaption == null || | |
| captions.pictureCaption == PictureCaption.none || | |
| position > captions.pictureCaption!.end || | |
| position < captions.pictureCaption!.start) |
|
|
||
| * Update the conditional statement for the `_currentCaptions`. | ||
| * Update plusplayer | ||
| 1. [DASH] Fix the issue where subtitles for content with pre-roll/insesrted ads in DASH could not be rendered. |
There was a problem hiding this comment.
No description provided.