page.dart 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:vid_player_demo/controller/player_controller.dart';
  4. import 'package:vid_player_demo/pages/canvas_player/view.dart';
  5. import 'package:vid_player_demo/pages/image_player/view.dart';
  6. class MultiCanvasPlayerPage extends StatefulWidget {
  7. const MultiCanvasPlayerPage({Key? key}) : super(key: key);
  8. @override
  9. _MultiCanvasPlayerPageState createState() => _MultiCanvasPlayerPageState();
  10. }
  11. class _MultiCanvasPlayerPageState extends State<MultiCanvasPlayerPage> {
  12. final vidURLs = [
  13. "http://cdn-bj.fis.plus/093BE20682B14BFB95D811F221A2B2FD.vid",
  14. "http://cdn-bj.fis.plus/f2d1607f66cc42d0b4a6f4e55afbaeca.vid",
  15. "http://cdn-bj.fis.plus/1fb270dbb35e448a8792eb46df882264.vid",
  16. "http://cdn-bj.fis.plus/95867692c39b4293bc0928192d1b53cb.vid",
  17. "http://cdn-bj.fis.plus/582ba3077ea64ace882a7e11577a842b.vid",
  18. "http://cdn-bj.fis.plus/ae37b3910cea406484f76da7b002708e.vid",
  19. "http://cdn-bj.fis.plus/1d21144f3e524477bb8471d8d66da603.vid",
  20. "http://cdn-bj.fis.plus/1fb270dbb35e448a8792eb46df882264.vid",
  21. "http://cdn-bj.fis.plus/95867692c39b4293bc0928192d1b53cb.vid",
  22. ];
  23. final _playerStateController = Get.put(PlayerStateController());
  24. @override
  25. void initState() {
  26. // TODO: implement initState
  27. super.initState();
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. return Scaffold(
  32. appBar: AppBar(
  33. title: const Text("多个播放器同时播放"),
  34. ),
  35. body: Column(
  36. children: [
  37. const SizedBox(height: 24),
  38. ElevatedButton(
  39. onPressed: () => {_playerStateController.play(context)},
  40. child: const Text("Play Together")),
  41. const SizedBox(height: 24),
  42. SizedBox(height: 800, child: buildPlayersGrid(vidURLs)),
  43. ],
  44. ));
  45. }
  46. Widget buildPlayersGrid(List<String> urls) {
  47. return GridView.count(
  48. crossAxisCount: 3,
  49. childAspectRatio: 1,
  50. shrinkWrap: true,
  51. children: urls
  52. .map((url) => CanvasPlayerView(url, viewSize: const Size(300, 300)))
  53. .toList(),
  54. );
  55. }
  56. @override
  57. void dispose() {
  58. super.dispose();
  59. Get.delete<PlayerStateController>();
  60. _playerStateController.dispose();
  61. }
  62. }