video_info.dart 1.2 KB

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