native_video_view_null_safe 0.5.0 native_video_view_null_safe: ^0.5.0 copied to clipboard
A video player widget displayed using the platform native player (VideoView in Android and AVPlayer in iOS).
import 'package:flutter/material.dart';
import 'package:native_video_view/native_video_view.dart';
void main() => runApp(MaterialApp(home: MyApp()));
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: _buildVideoPlayerWidget(),
);
}
Widget _buildVideoPlayerWidget() {
return Container(
alignment: Alignment.center,
child: NativeVideoView(
keepAspectRatio: true,
showMediaController: true,
enableVolumeControl: true,
onCreated: (controller) {
controller.setVideoSource(
'https://kdweb-75176.gzc.vod.tencent-cloud.com/video_test_src/video_quality_improve_demo/NewYork_4K_HDR.mp4',
sourceType: VideoSourceType.network,
requestAudioFocus: true,
);
},
onPrepared: (controller, info) {
controller.play();
},
onError: (controller, what, extra, message) {
print('Player Error ($what | $extra | $message)');
},
onCompletion: (controller) {
print('Video completed');
},
),
);
}
}