main.dart 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_ijkplayer/flutter_ijkplayer.dart';
  3. import 'package:permission/permission.dart';
  4. void main() => runApp(MyApp());
  5. class MyApp extends StatefulWidget {
  6. @override
  7. _MyAppState createState() => _MyAppState();
  8. }
  9. class _MyAppState extends State<MyApp> {
  10. @override
  11. Widget build(BuildContext context) {
  12. return MaterialApp(
  13. home: HomePage(),
  14. );
  15. }
  16. }
  17. class HomePage extends StatefulWidget {
  18. @override
  19. HomePageState createState() => HomePageState();
  20. }
  21. class HomePageState extends State<HomePage> {
  22. IjkController controller = IjkController();
  23. @override
  24. void initState() {
  25. super.initState();
  26. controller.initIjk();
  27. }
  28. @override
  29. void dispose() {
  30. controller.dispose();
  31. super.dispose();
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. return Scaffold(
  36. appBar: AppBar(
  37. title: const Text('Plugin example app'),
  38. ),
  39. body: Container(
  40. // width: MediaQuery.of(context).size.width,
  41. // height: 400,
  42. child: Column(
  43. children: <Widget>[
  44. AspectRatio(
  45. aspectRatio: 1280 / 720,
  46. child: IjkPlayer(
  47. controller: controller,
  48. ),
  49. ),
  50. ],
  51. ),
  52. ),
  53. floatingActionButton: FloatingActionButton(
  54. child: Icon(Icons.play_arrow),
  55. onPressed: () async {
  56. await Permission.requestPermissions([PermissionName.Storage]);
  57. await controller.initIjk();
  58. await controller.setNetData(
  59. 'https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4',
  60. // "file:///sdcard/Download/Sample1.mp4",
  61. );
  62. controller.play();
  63. },
  64. ),
  65. );
  66. }
  67. }