Skip to content

Commit

Permalink
feat: lazy init surface after prepared (#148)
Browse files Browse the repository at this point in the history
  • Loading branch information
befovy committed Dec 20, 2019
1 parent 3bcae22 commit 2889371
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 28 deletions.
35 changes: 28 additions & 7 deletions example/pubspec.lock
Expand Up @@ -14,7 +14,7 @@ packages:
name: archive
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.0.10"
version: "2.0.11"
args:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: async
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.3.0"
version: "2.4.0"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -57,6 +57,13 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.1.1"
coverage:
dependency: transitive
description:
name: coverage
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.13.3+3"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -189,20 +196,27 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.3.19"
logging:
dependency: transitive
description:
name: logging
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.11.3+2"
matcher:
dependency: transitive
description:
name: matcher
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.12.5"
version: "0.12.6"
meta:
dependency: transitive
description:
name: meta
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "1.1.7"
version: "1.1.8"
mime:
dependency: transitive
description:
Expand Down Expand Up @@ -424,21 +438,21 @@ packages:
name: test
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "1.6.3"
version: "1.9.4"
test_api:
dependency: transitive
description:
name: test_api
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.2.5"
version: "0.2.11"
test_core:
dependency: transitive
description:
name: test_core
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.2.5"
version: "0.2.15"
typed_data:
dependency: transitive
description:
Expand All @@ -453,6 +467,13 @@ packages:
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.0.8"
vm_service:
dependency: transitive
description:
name: vm_service
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.1.4"
vm_service_client:
dependency: transitive
description:
Expand Down
44 changes: 28 additions & 16 deletions lib/core/fijkview.dart
Expand Up @@ -151,10 +151,10 @@ class FijkView extends StatefulWidget {
final double height;

/// Enable or disable the full screen
///
///
/// If [fs] is true, FijkView make response to the [FijkValue.fullScreen] value changed,
/// and push o new full screen mode page when [FijkValue.fullScreen] is true, pop full screen page when [FijkValue.fullScreen] become false.
///
///
/// If [fs] is false, FijkView never make response to the change of [FijkValue.fullScreen].
/// But you can still call [FijkPlayer.enterFullScreen] and [FijkPlayer.exitFullScreen] and make your own full screen pages.
final bool fs;
Expand All @@ -174,39 +174,51 @@ class _FijkViewState extends State<FijkView> {
@override
void initState() {
super.initState();
_nativeSetup();
Size s = widget.player.value.size;
if (s != null) {
_vWidth = s.width;
_vHeight = s.height;
}
if (widget.fs) {
widget.player.addListener(_fijkValueListener);
}
widget.player.addListener(_fijkValueListener);
_nativeSetup();
}

Future<void> _nativeSetup() async {
if (widget.player.value.prepared) {
_setupTexture();
}
paramNotifier.value = paramNotifier.value + 1;
}

void _setupTexture() async {
final int vid = await widget.player.setupSurface();
FijkLog.i("view setup, vid:" + vid.toString());
setState(() {
_textureId = vid;
});
paramNotifier.value = paramNotifier.value + 1;
}

void _fijkValueListener() async {
FijkValue value = widget.player.value;
if (value.fullScreen && !_fullScreen) {
_fullScreen = true;
await _pushFullScreenWidget(context);
} else if (_fullScreen && !value.fullScreen) {
Navigator.of(context).pop();
_fullScreen = false;
if (value.prepared && _textureId < 0) {
_setupTexture();
}

if (value.size != null && value.prepared) {
_vWidth = value.size.width;
_vHeight = value.size.height;
if (widget.fs) {
if (value.fullScreen && !_fullScreen) {
_fullScreen = true;
await _pushFullScreenWidget(context);
} else if (_fullScreen && !value.fullScreen) {
Navigator.of(context).pop();
_fullScreen = false;
}

// save width and height to make judgement about whether to
// request landscape when enter full screen mode
if (value.size != null && value.prepared) {
_vWidth = value.size.width;
_vHeight = value.size.height;
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions pubspec.lock
Expand Up @@ -7,7 +7,7 @@ packages:
name: archive
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.0.10"
version: "2.0.11"
args:
dependency: transitive
description:
Expand All @@ -21,7 +21,7 @@ packages:
name: async
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "2.3.0"
version: "2.4.0"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -80,14 +80,14 @@ packages:
name: matcher
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.12.5"
version: "0.12.6"
meta:
dependency: transitive
description:
name: meta
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "1.1.7"
version: "1.1.8"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -162,7 +162,7 @@ packages:
name: test_api
url: "https://mirrors.tuna.tsinghua.edu.cn/dart-pub/"
source: hosted
version: "0.2.5"
version: "0.2.11"
typed_data:
dependency: transitive
description:
Expand Down

0 comments on commit 2889371

Please sign in to comment.