ijkplayer_builder.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_ijkplayer/flutter_ijkplayer.dart';
  3. /// Player builder, Inheritance of this class allows you to implement your own player
  4. typedef Widget IJKTextureBuilder(
  5. BuildContext context,
  6. IjkMediaController controller,
  7. VideoInfo info,
  8. );
  9. /// default IJKPlayer method
  10. Widget buildDefaultIjkPlayer(
  11. BuildContext context,
  12. IjkMediaController controller,
  13. VideoInfo info,
  14. ) {
  15. return DefaultIJKPlayerWrapper(
  16. controller: controller,
  17. info: info,
  18. );
  19. }
  20. /// Default IJKPlayer Wrapper
  21. ///
  22. /// This widget solves the aspect ratio problem in video direction.
  23. class DefaultIJKPlayerWrapper extends StatelessWidget {
  24. final IjkMediaController controller;
  25. final VideoInfo info;
  26. const DefaultIJKPlayerWrapper({
  27. Key key,
  28. this.controller,
  29. this.info,
  30. }) : super(key: key);
  31. @override
  32. Widget build(BuildContext context) {
  33. double ratio = info?.ratio ?? 1280 / 720;
  34. var id = controller.textureId;
  35. if (id == null) {
  36. return AspectRatio(
  37. aspectRatio: ratio,
  38. child: Container(
  39. color: Colors.black,
  40. ),
  41. );
  42. }
  43. Widget w = Container(
  44. color: Colors.black,
  45. child: Texture(
  46. textureId: id,
  47. ),
  48. );
  49. if (!controller.autoRotate) {
  50. return AspectRatio(
  51. aspectRatio: null,
  52. child: w,
  53. );
  54. }
  55. int degree = info?.degree ?? 0;
  56. if (ratio == 0) {
  57. ratio = 1280 / 720;
  58. }
  59. w = AspectRatio(
  60. aspectRatio: ratio,
  61. child: w,
  62. );
  63. if (degree != 0) {
  64. w = RotatedBox(
  65. quarterTurns: degree ~/ 90,
  66. child: w,
  67. );
  68. }
  69. return Container(
  70. child: w,
  71. alignment: Alignment.center,
  72. color: Colors.black,
  73. );
  74. }
  75. }