manager.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. part of '../ijkplayer.dart';
  2. /// create 2019/3/18 by cai
  3. ///
  4. class IjkManager {
  5. /// For the hot reload/ hot restart to release last texture resource. Release version does not have hot reload, so you can not call it.
  6. ///
  7. /// release版本可不调用, 主要是为了释放hot restart/hot reload的资源,因为原生资源不参与热重载
  8. ///
  9. ///
  10. /// If this method is not invoked in the debug version, the sound before the hot reload will continue to play.
  11. static Future<void> initIJKPlayer() async {
  12. await _globalChannel.invokeMethod("init");
  13. }
  14. /// set system volume
  15. static Future<void> setSystemVolume(int volume) async {
  16. await _globalChannel.invokeMethod("setSystemVolume", {
  17. "volume": volume,
  18. });
  19. }
  20. /// get system volume
  21. static Future<int> getSystemVolume() async {
  22. return _globalChannel.invokeMethod("getSystemVolume");
  23. }
  24. static Future<int> systemVolumeUp() async {
  25. return _globalChannel.invokeMethod("volumeUp");
  26. }
  27. static Future<int> systemVolumeDown() async {
  28. return _globalChannel.invokeMethod("volumeDown");
  29. }
  30. static Future<void> hideSystemVolumeBar() async {
  31. if (Platform.isIOS) {
  32. return _globalChannel.invokeMethod("hideSystemVolumeBar");
  33. }
  34. }
  35. static Future<void> setSystemBrightness(double brightness) async {
  36. await _globalChannel.invokeMethod("setSystemBrightness", <String, dynamic>{
  37. "brightness": brightness,
  38. });
  39. }
  40. static Future<double> getSystemBrightness() async {
  41. return _globalChannel.invokeMethod("getSystemBrightness");
  42. }
  43. static Future<void> resetBrightness() async {
  44. await _globalChannel.invokeMethod("resetBrightness");
  45. }
  46. static setLandScape() async {
  47. if (Platform.isAndroid) {
  48. SystemChrome.setPreferredOrientations(
  49. [DeviceOrientation.landscapeLeft],
  50. );
  51. SystemChrome.setEnabledSystemUIOverlays([]);
  52. } else if (Platform.isIOS) {
  53. await setSupportOrientation([
  54. DeviceOrientation.landscapeLeft,
  55. DeviceOrientation.landscapeRight,
  56. ]);
  57. setCurrentOrientation(DeviceOrientation.landscapeLeft);
  58. }
  59. }
  60. static setPortrait() async {
  61. if (Platform.isAndroid) {
  62. await SystemChrome.setPreferredOrientations([
  63. DeviceOrientation.portraitUp,
  64. ]);
  65. SystemChrome.restoreSystemUIOverlays();
  66. showSystemOverlay();
  67. } else if (Platform.isIOS) {
  68. await unlockOrientation();
  69. setCurrentOrientation(DeviceOrientation.portraitUp);
  70. }
  71. }
  72. static showSystemOverlay() {
  73. SystemChrome.setEnabledSystemUIOverlays(const [
  74. SystemUiOverlay.top,
  75. SystemUiOverlay.bottom,
  76. ]);
  77. }
  78. static setSupportOrientation(List<DeviceOrientation> orientations) async {
  79. if (orientations.isEmpty) {
  80. return;
  81. }
  82. if (Platform.isAndroid) {
  83. await SystemChrome.setPreferredOrientations(orientations);
  84. SystemChrome.restoreSystemUIOverlays();
  85. } else if (Platform.isIOS) {
  86. var orientationIndexList = orientations.map((o) => o.index).toList();
  87. await _globalChannel.invokeMethod(
  88. "setSupportOrientation",
  89. <String, dynamic>{
  90. "supportOrientation": orientationIndexList,
  91. },
  92. );
  93. }
  94. }
  95. static setCurrentOrientation(DeviceOrientation orientation) async {
  96. if (orientation == null) {
  97. return;
  98. }
  99. if (Platform.isAndroid) {
  100. } else if (Platform.isIOS) {
  101. await _globalChannel.invokeMethod(
  102. "setCurrentOrientation",
  103. <String, dynamic>{
  104. "target": orientation.index,
  105. },
  106. );
  107. }
  108. }
  109. static unlockOrientation() async {
  110. if (Platform.isAndroid) {
  111. await SystemChrome.setPreferredOrientations([
  112. DeviceOrientation.landscapeLeft,
  113. DeviceOrientation.landscapeRight,
  114. DeviceOrientation.portraitUp,
  115. DeviceOrientation.portraitDown,
  116. ]);
  117. await SystemChrome.restoreSystemUIOverlays();
  118. showSystemOverlay();
  119. } else if (Platform.isIOS) {
  120. _globalChannel.invokeMethod("unlockOrientation");
  121. }
  122. }
  123. }