Video demo instrumentation (#25489)
* Video Demo instrumentation * Video Demo instrumentation * Updated per review * Fixed a typo
This commit is contained in:
parent
49e67e2ed0
commit
8b34a12d45
@ -9,13 +9,8 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:video_player/video_player.dart';
|
import 'package:video_player/video_player.dart';
|
||||||
import 'package:device_info/device_info.dart';
|
import 'package:device_info/device_info.dart';
|
||||||
|
|
||||||
// TODO(sigurdm): This should not be stored here.
|
|
||||||
const String beeUri =
|
|
||||||
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4';
|
|
||||||
|
|
||||||
class VideoCard extends StatelessWidget {
|
class VideoCard extends StatelessWidget {
|
||||||
const VideoCard({Key key, this.controller, this.title, this.subtitle})
|
const VideoCard({ Key key, this.controller, this.title, this.subtitle }) : super(key: key);
|
||||||
: super(key: key);
|
|
||||||
|
|
||||||
final VideoPlayerController controller;
|
final VideoPlayerController controller;
|
||||||
final String title;
|
final String title;
|
||||||
@ -214,8 +209,7 @@ class FadeAnimation extends StatefulWidget {
|
|||||||
_FadeAnimationState createState() => _FadeAnimationState();
|
_FadeAnimationState createState() => _FadeAnimationState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FadeAnimationState extends State<FadeAnimation>
|
class _FadeAnimationState extends State<FadeAnimation> with SingleTickerProviderStateMixin {
|
||||||
with SingleTickerProviderStateMixin {
|
|
||||||
AnimationController animationController;
|
AnimationController animationController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -336,7 +330,7 @@ class _ConnectivityOverlayState extends State<ConnectivityOverlay> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class VideoDemo extends StatefulWidget {
|
class VideoDemo extends StatefulWidget {
|
||||||
const VideoDemo({Key key}) : super(key: key);
|
const VideoDemo({ Key key }) : super(key: key);
|
||||||
|
|
||||||
static const String routeName = '/video';
|
static const String routeName = '/video';
|
||||||
|
|
||||||
@ -350,37 +344,40 @@ Future<bool> isIOSSimulator() async {
|
|||||||
return Platform.isIOS && !(await deviceInfoPlugin.iosInfo).isPhysicalDevice;
|
return Platform.isIOS && !(await deviceInfoPlugin.iosInfo).isPhysicalDevice;
|
||||||
}
|
}
|
||||||
|
|
||||||
class _VideoDemoState extends State<VideoDemo>
|
class _VideoDemoState extends State<VideoDemo> with SingleTickerProviderStateMixin {
|
||||||
with SingleTickerProviderStateMixin {
|
final VideoPlayerController butterflyController = VideoPlayerController.asset(
|
||||||
final VideoPlayerController butterflyController =
|
'videos/butterfly.mp4',
|
||||||
VideoPlayerController.asset(
|
package: 'flutter_gallery_assets',
|
||||||
'videos/butterfly.mp4',
|
|
||||||
package: 'flutter_gallery_assets',
|
|
||||||
);
|
|
||||||
final VideoPlayerController beeController = VideoPlayerController.network(
|
|
||||||
beeUri,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO(sigurdm): This should not be stored here.
|
||||||
|
static const String beeUri = 'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4';
|
||||||
|
final VideoPlayerController beeController = VideoPlayerController.network(beeUri);
|
||||||
|
|
||||||
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
|
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
|
||||||
final Completer<void> connectedCompleter = Completer<void>();
|
final Completer<void> connectedCompleter = Completer<void>();
|
||||||
bool isSupported = true;
|
bool isSupported = true;
|
||||||
|
bool isDisposed = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
Future<void> initController(VideoPlayerController controller) async {
|
Future<void> initController(VideoPlayerController controller, String name) async {
|
||||||
|
print('> VideoDemo initController "$name" ${isDisposed ? "DISPOSED" : ""}');
|
||||||
controller.setLooping(true);
|
controller.setLooping(true);
|
||||||
controller.setVolume(0.0);
|
controller.setVolume(0.0);
|
||||||
controller.play();
|
controller.play();
|
||||||
await connectedCompleter.future;
|
await connectedCompleter.future;
|
||||||
await controller.initialize();
|
await controller.initialize();
|
||||||
if (mounted)
|
if (mounted) {
|
||||||
|
print('< VideoDemo initController "$name" done ${isDisposed ? "DISPOSED" : ""}');
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initController(butterflyController);
|
initController(butterflyController, 'butterfly');
|
||||||
initController(beeController);
|
initController(beeController, 'bee');
|
||||||
isIOSSimulator().then<void>((bool result) {
|
isIOSSimulator().then<void>((bool result) {
|
||||||
isSupported = !result;
|
isSupported = !result;
|
||||||
});
|
});
|
||||||
@ -388,8 +385,11 @@ class _VideoDemoState extends State<VideoDemo>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
print('> VideoDemo dispose');
|
||||||
|
isDisposed = true;
|
||||||
butterflyController.dispose();
|
butterflyController.dispose();
|
||||||
beeController.dispose();
|
beeController.dispose();
|
||||||
|
print('< VideoDemo dispose');
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -401,29 +401,29 @@ class _VideoDemoState extends State<VideoDemo>
|
|||||||
title: const Text('Videos'),
|
title: const Text('Videos'),
|
||||||
),
|
),
|
||||||
body: isSupported
|
body: isSupported
|
||||||
? ConnectivityOverlay(
|
? ConnectivityOverlay(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
VideoCard(
|
VideoCard(
|
||||||
title: 'Butterfly',
|
title: 'Butterfly',
|
||||||
subtitle: '… flutters by',
|
subtitle: '… flutters by',
|
||||||
controller: butterflyController,
|
controller: butterflyController,
|
||||||
),
|
),
|
||||||
VideoCard(
|
VideoCard(
|
||||||
title: 'Bee',
|
title: 'Bee',
|
||||||
subtitle: '… gently buzzing',
|
subtitle: '… gently buzzing',
|
||||||
controller: beeController,
|
controller: beeController,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
|
||||||
connectedCompleter: connectedCompleter,
|
|
||||||
scaffoldKey: scaffoldKey,
|
|
||||||
)
|
|
||||||
: const Center(
|
|
||||||
child: Text(
|
|
||||||
'Video playback not supported on the iOS Simulator.',
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
connectedCompleter: connectedCompleter,
|
||||||
|
scaffoldKey: scaffoldKey,
|
||||||
|
)
|
||||||
|
: const Center(
|
||||||
|
child: Text(
|
||||||
|
'Video playback not supported on the iOS Simulator.',
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user