VideoLocation.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. package com.yc.videosqllite.model;
  2. import android.os.Build;
  3. import org.json.JSONException;
  4. import org.json.JSONObject;
  5. import java.io.Serializable;
  6. import java.util.Arrays;
  7. import java.util.Objects;
  8. /**
  9. * <pre>
  10. * @author yangchong
  11. * email : yangchong211@163.com
  12. * time : 2020/8/6
  13. * desc : 音视频bean
  14. * revise: 必须
  15. * </pre>
  16. */
  17. public class VideoLocation implements Serializable {
  18. /**
  19. * 视频链接
  20. */
  21. private String url;
  22. /**
  23. * 视频链接md5
  24. */
  25. private String urlMd5;
  26. /**
  27. * 视频播放位置
  28. */
  29. private long position;
  30. /**
  31. * 视频总时间
  32. */
  33. private long totalTime;
  34. public VideoLocation(){
  35. }
  36. public VideoLocation(String url, long position, long totalTime) {
  37. this.url = url;
  38. this.position = position;
  39. this.totalTime = totalTime;
  40. }
  41. /*public VideoLocation(String url, String urlMd5, long position, long totalTime) {
  42. this.url = url;
  43. this.urlMd5 = urlMd5;
  44. this.position = position;
  45. this.totalTime = totalTime;
  46. }*/
  47. public String getUrl() {
  48. return url;
  49. }
  50. public void setUrl(String url) {
  51. this.url = url;
  52. }
  53. public String getUrlMd5() {
  54. return urlMd5;
  55. }
  56. public void setUrlMd5(String urlMd5) {
  57. this.urlMd5 = urlMd5;
  58. }
  59. public long getPosition() {
  60. return position;
  61. }
  62. public void setPosition(long position) {
  63. this.position = position;
  64. }
  65. public long getTotalTime() {
  66. return totalTime;
  67. }
  68. public void setTotalTime(long totalTime) {
  69. this.totalTime = totalTime;
  70. }
  71. public String toJson() {
  72. JSONObject jsonObject= new JSONObject();
  73. try {
  74. jsonObject.put("url", getUrl());
  75. jsonObject.put("urlMd5", getUrlMd5());
  76. jsonObject.put("position", getPosition());
  77. jsonObject.put("totalTime", getTotalTime());
  78. return jsonObject.toString();
  79. } catch (JSONException e) {
  80. e.printStackTrace();
  81. }
  82. return null;
  83. }
  84. public static com.yc.videosqllite.model.VideoLocation toObject(String jsonStr) {
  85. com.yc.videosqllite.model.VideoLocation m = new com.yc.videosqllite.model.VideoLocation();
  86. try {
  87. JSONObject jsonObject = new JSONObject(jsonStr);
  88. m.setUrl(jsonObject.has("url") ? jsonObject.getString("url"):null);
  89. m.setUrlMd5(jsonObject.has("urlMd5") ? jsonObject.getString("urlMd5"):null);
  90. m.setPosition(jsonObject.has("position") ? jsonObject.getLong("position"):0);
  91. m.setTotalTime(jsonObject.has("totalTime") ? jsonObject.getLong("totalTime"):0);
  92. return m;
  93. } catch (JSONException e) {
  94. e.printStackTrace();
  95. }
  96. return m;
  97. }
  98. @Override
  99. public String toString() {
  100. return "VideoLocation{" +
  101. "url='" + url + '\'' +
  102. ", urlMd5='" + urlMd5 + '\'' +
  103. ", position=" + position +
  104. ", totalTime=" + totalTime +
  105. '}';
  106. }
  107. @Override
  108. public boolean equals(Object o) {
  109. if (this == o){
  110. return true;
  111. }
  112. if (o == null || getClass() != o.getClass()) {
  113. return false;
  114. }
  115. com.yc.videosqllite.model.VideoLocation location = (com.yc.videosqllite.model.VideoLocation) o;
  116. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  117. return position == location.position &&
  118. totalTime == location.totalTime &&
  119. Objects.equals(url, location.url) &&
  120. Objects.equals(urlMd5, location.urlMd5);
  121. } else {
  122. return position == location.position &&
  123. totalTime == location.totalTime &&
  124. equals(url,location.url) &&
  125. equals(urlMd5,location.urlMd5);
  126. }
  127. }
  128. @Override
  129. public int hashCode() {
  130. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  131. return Objects.hash(url, urlMd5, position, totalTime);
  132. }
  133. return hash(url,urlMd5,position,totalTime);
  134. }
  135. /**
  136. * 比较两个对象
  137. * @param a a对象
  138. * @param b b对象
  139. * @return
  140. */
  141. private boolean equals(Object a, Object b) {
  142. boolean ab = (a == b);
  143. boolean equal = (a != null && a.equals(b));
  144. return ab || equal;
  145. }
  146. /**
  147. * hash算法
  148. * @param values 参数
  149. * @return
  150. */
  151. private int hash(Object... values) {
  152. return Arrays.hashCode(values);
  153. }
  154. }