video_info.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import 'dart:convert';
  2. /// about video info
  3. class VideoInfo {
  4. /// Width of Video
  5. int width;
  6. /// Height of Video
  7. int height;
  8. /// Total length of video
  9. double duration;
  10. /// Current playback progress
  11. double currentPosition;
  12. /// In play
  13. bool isPlaying;
  14. /// Degree of Video
  15. int degree;
  16. /// The media tcp speed, unit is byte
  17. int tcpSpeed;
  18. Map<String, dynamic> _map;
  19. /// Percentage playback progress
  20. double get progress => (currentPosition ?? 0) / (duration ?? 1);
  21. ///Is there any information?
  22. bool get hasData => _map != null;
  23. /// Aspect ratio
  24. double get ratio {
  25. double r;
  26. if (width != null && height != null) {
  27. if (width == 0 || height == 0) {
  28. r = 1280 / 720;
  29. } else {
  30. r = width / height;
  31. }
  32. } else {
  33. r = 1280 / 720;
  34. }
  35. return r;
  36. }
  37. /// Constructing from the native method
  38. VideoInfo.fromMap(Map<String, dynamic> map) {
  39. if (map == null) {
  40. return;
  41. }
  42. this._map = map;
  43. this.width = map["width"];
  44. this.height = map["height"];
  45. this.duration = map["duration"];
  46. this.currentPosition = map["currentPosition"];
  47. this.isPlaying = map["isPlaying"];
  48. this.degree = map["degree"];
  49. this.tcpSpeed = map["tcpSpeed"];
  50. }
  51. @override
  52. String toString() {
  53. if (_map == null) {
  54. return "null";
  55. }
  56. return json.encode(_map);
  57. }
  58. }