Skip to content

Commit

Permalink
fix: Fix VideoViewController state not correct when the AgoraVideoVie…
Browse files Browse the repository at this point in the history
…w is reused
  • Loading branch information
littleGnAl committed Jun 28, 2023
1 parent bcc5561 commit 37e4a21
Show file tree
Hide file tree
Showing 4 changed files with 590 additions and 222 deletions.
12 changes: 5 additions & 7 deletions lib/src/impl/agora_video_view_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ class _AgoraRtcRenderPlatformViewState extends State<AgoraRtcRenderPlatformView>
if (!oldWidget.controller.isSame(widget.controller)) {
await oldWidget.controller.disposeRender();
await _setupVideo();
} else {
_controller(widget.controller).updateController(oldWidget.controller);
}
}

Expand Down Expand Up @@ -243,13 +245,9 @@ class _AgoraRtcRenderTextureState extends State<AgoraRtcRenderTexture>

Future<void> _didUpdateWidget(
covariant AgoraRtcRenderTexture oldWidget) async {
if (!oldWidget.controller.isSame(widget.controller)) {
await oldWidget.controller.dispose();
if (!mounted) return;
_initialize();
} else {
widget.controller.setTextureId(oldWidget.controller.getTextureId());
}
// For flutter texture rendering, only update the texture id and other state, and the
// Flutter framework will handle the rest.
_controller(widget.controller).updateController(oldWidget.controller);
}

@override
Expand Down
10 changes: 7 additions & 3 deletions lib/src/impl/video_view_controller_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,13 @@ mixin VideoViewControllerBaseMixin implements VideoViewControllerBase {
@override
int getTextureId() => _textureId;

@override
void setTextureId(int textureId) {
_textureId = textureId;
@internal
void updateController(VideoViewControllerBase oldController) {
assert(oldController is VideoViewControllerBaseMixin);
final oldControllerMixin = oldController as VideoViewControllerBaseMixin;
_textureId = oldControllerMixin.getTextureId();
_isCreatedRender = oldControllerMixin._isCreatedRender;
_isDisposeRender = oldControllerMixin._isDisposeRender;
}

@override
Expand Down
3 changes: 0 additions & 3 deletions lib/src/render/video_view_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ abstract class VideoViewControllerBase {
/// Whether to use Android SurfaceView to render video:true: Use Android SurfaceView to render video.false: Do not use Android SurfaceView to render video.Android SurfaceView applies to Android platform only.
bool get useAndroidSurfaceView;

@internal
void setTextureId(int textureId);

@internal
int getTextureId();

Expand Down
Loading

0 comments on commit 37e4a21

Please sign in to comment.