manager.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 Future<void> _setOrientation(List<DeviceOrientation> list) async {
  47. if (Platform.isAndroid) {
  48. SystemChrome.setPreferredOrientations(list);
  49. } else if (Platform.isIOS) {
  50. var orientations = list.map((v) => v.index).toList();
  51. if (list.isEmpty) {
  52. _globalChannel.invokeMethod("unlockOrientation");
  53. } else {
  54. _globalChannel.invokeMethod(
  55. "setOrientation",
  56. {
  57. "orientation": orientations,
  58. },
  59. );
  60. }
  61. }
  62. }
  63. static setLandScapeLeft() {
  64. if (Platform.isAndroid) {
  65. SystemChrome.setPreferredOrientations(
  66. [DeviceOrientation.landscapeLeft],
  67. );
  68. } else if (Platform.isIOS) {
  69. _setOrientation(
  70. [DeviceOrientation.landscapeLeft],
  71. );
  72. }
  73. }
  74. static portraitUp() async {
  75. if (Platform.isAndroid) {
  76. await SystemChrome.setPreferredOrientations([
  77. DeviceOrientation.portraitUp,
  78. ]);
  79. await SystemChrome.restoreSystemUIOverlays();
  80. } else {
  81. _setOrientation(
  82. [DeviceOrientation.portraitUp],
  83. );
  84. }
  85. }
  86. static unlockOrientation() async {
  87. if (Platform.isAndroid) {
  88. await SystemChrome.setPreferredOrientations([
  89. DeviceOrientation.landscapeLeft,
  90. DeviceOrientation.landscapeRight,
  91. DeviceOrientation.portraitUp,
  92. ]);
  93. await SystemChrome.restoreSystemUIOverlays();
  94. } else if (Platform.isIOS) {
  95. await _setOrientation([]);
  96. await SystemChrome.restoreSystemUIOverlays();
  97. }
  98. }
  99. }