video: prevent frame capture when video is not ready
This commit is contained in:
parent
2e1622fc88
commit
7bedca9537
3 changed files with 32 additions and 2 deletions
|
@ -245,6 +245,18 @@ class _ButtonRow extends StatelessWidget {
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case VideoAction.captureFrame:
|
case VideoAction.captureFrame:
|
||||||
|
child = ValueListenableBuilder<bool>(
|
||||||
|
valueListenable: controller?.renderingVideoNotifier ?? ValueNotifier(false),
|
||||||
|
builder: (context, canDo, child) {
|
||||||
|
return IconButton(
|
||||||
|
icon: child!,
|
||||||
|
onPressed: canDo ? onPressed : null,
|
||||||
|
tooltip: action.getText(context),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Icon(action.getIcon()),
|
||||||
|
);
|
||||||
|
break;
|
||||||
case VideoAction.replay10:
|
case VideoAction.replay10:
|
||||||
case VideoAction.selectStreams:
|
case VideoAction.selectStreams:
|
||||||
case VideoAction.setSpeed:
|
case VideoAction.setSpeed:
|
||||||
|
@ -265,6 +277,7 @@ class _ButtonRow extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
PopupMenuEntry<VideoAction> _buildPopupMenuItem(BuildContext context, VideoAction action) {
|
PopupMenuEntry<VideoAction> _buildPopupMenuItem(BuildContext context, VideoAction action) {
|
||||||
|
var enabled = true;
|
||||||
Widget? child;
|
Widget? child;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case VideoAction.togglePlay:
|
case VideoAction.togglePlay:
|
||||||
|
@ -274,6 +287,9 @@ class _ButtonRow extends StatelessWidget {
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case VideoAction.captureFrame:
|
case VideoAction.captureFrame:
|
||||||
|
enabled = controller?.renderingVideoNotifier.value ?? false;
|
||||||
|
child = MenuRow(text: action.getText(context), icon: action.getIcon());
|
||||||
|
break;
|
||||||
case VideoAction.replay10:
|
case VideoAction.replay10:
|
||||||
case VideoAction.selectStreams:
|
case VideoAction.selectStreams:
|
||||||
case VideoAction.setSpeed:
|
case VideoAction.setSpeed:
|
||||||
|
@ -282,6 +298,7 @@ class _ButtonRow extends StatelessWidget {
|
||||||
}
|
}
|
||||||
return PopupMenuItem(
|
return PopupMenuItem(
|
||||||
value: action,
|
value: action,
|
||||||
|
enabled: enabled,
|
||||||
child: child,
|
child: child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,8 @@ abstract class AvesVideoController {
|
||||||
|
|
||||||
Stream<VideoStatus> get statusStream;
|
Stream<VideoStatus> get statusStream;
|
||||||
|
|
||||||
|
ValueNotifier<bool> get renderingVideoNotifier;
|
||||||
|
|
||||||
bool get isReady;
|
bool get isReady;
|
||||||
|
|
||||||
bool get isPlaying => status == VideoStatus.playing;
|
bool get isPlaying => status == VideoStatus.playing;
|
||||||
|
|
|
@ -38,6 +38,9 @@ class IjkPlayerAvesVideoController extends AvesVideoController {
|
||||||
@override
|
@override
|
||||||
final double maxSpeed = 2;
|
final double maxSpeed = 2;
|
||||||
|
|
||||||
|
@override
|
||||||
|
final ValueNotifier<bool> renderingVideoNotifier = ValueNotifier(false);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
final ValueNotifier<double> sarNotifier = ValueNotifier(1);
|
final ValueNotifier<double> sarNotifier = ValueNotifier(1);
|
||||||
|
|
||||||
|
@ -52,6 +55,10 @@ class IjkPlayerAvesVideoController extends AvesVideoController {
|
||||||
_staticInitialized = true;
|
_staticInitialized = true;
|
||||||
}
|
}
|
||||||
_instance = FijkPlayer();
|
_instance = FijkPlayer();
|
||||||
|
_valueStream.firstWhere((value) => value.videoRenderStart).then(
|
||||||
|
(value) => renderingVideoNotifier.value = true,
|
||||||
|
onError: (error) {},
|
||||||
|
);
|
||||||
_startListening();
|
_startListening();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,9 +347,13 @@ class IjkPlayerAvesVideoController extends AvesVideoController {
|
||||||
return Map.fromEntries(_streams.map((stream) => MapEntry(stream, selectedIndices.contains(stream.index))));
|
return Map.fromEntries(_streams.map((stream) => MapEntry(stream, selectedIndices.contains(stream.index))));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO TLAD [video] bug: crash when video stream is not supported
|
|
||||||
@override
|
@override
|
||||||
Future<Uint8List> captureFrame() => _instance.takeSnapShot();
|
Future<Uint8List> captureFrame() {
|
||||||
|
if (!_instance.value.videoRenderStart) {
|
||||||
|
return Future.error('cannot capture frame when video is not rendered');
|
||||||
|
}
|
||||||
|
return _instance.takeSnapShot();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildPlayerWidget(BuildContext context) {
|
Widget buildPlayerWidget(BuildContext context) {
|
||||||
|
|
Loading…
Reference in a new issue