main.dart 1.8 KB

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