66
77import com .tencent .liteav .basic .log .TXCLog ;
88import com .tencent .liteav .demo .play .bean .TCPlayInfoStream ;
9+ import com .tencent .liteav .demo .play .protocol .TCPlayInfoParserV2 ;
10+ import com .tencent .liteav .demo .play .protocol .TCPlayInfoParserV4 ;
911
1012import org .json .JSONArray ;
1113import org .json .JSONException ;
2325
2426/**
2527 * Created by liyuejiao on 2018/7/3.
26- * 获取点播信息
27- */
28+ * 获取点播信息
29+ */
2830
2931public class SuperVodListLoader {
30-
32+ public static final int LOADINFO_ERROR_CODE_NORMAL = - 1 ;
3133 private static final String TAG = "SuperVodListLoader" ;
3234 private static SuperVodListLoader sInstance ;
3335 private Handler mHandler ;
@@ -66,23 +68,22 @@ public ArrayList<VideoModel> loadDefaultVodList() {
6668 VideoModel model = null ;
6769
6870
69-
7071 model = new VideoModel ();
7172 model .appid = 1252463788 ;
7273 model .fileid = "5285890781763144364" ;
7374 list .add (model );
7475
7576 model = new VideoModel ();
76- model .appid = 1252463788 ;
77- model .fileid = "4564972819220421305 " ;
77+ model .appid = 1400329073 ;
78+ model .fileid = "5285890800381567412 " ;
7879 list .add (model );
7980
8081 model = new VideoModel ();
81- model .appid = 1252463788 ;
82- model .fileid = "4564972819219071568 " ;
82+ model .appid = 1400329073 ;
83+ model .fileid = "5285890800381530399 " ;
8384 list .add (model );
8485
85- model = new VideoModel ();
86+ model = new VideoModel ();
8687 model .appid = 1252463788 ;
8788 model .fileid = "4564972819219071668" ;
8889 list .add (model );
@@ -99,6 +100,7 @@ public ArrayList<VideoModel> loadDefaultVodList() {
99100
100101 return list ;
101102 }
103+
102104 public void getVodInfoOneByOne (ArrayList <VideoModel > videoModels ) {
103105 if (videoModels == null || videoModels .size () == 0 )
104106 return ;
@@ -120,7 +122,7 @@ public void run() {
120122 public void onFailure (Call call , IOException e ) {
121123 //获取请求信息失败
122124 if (mOnVodInfoLoadListener != null ) {
123- mOnVodInfoLoadListener .onFail (- 1 );
125+ mOnVodInfoLoadListener .onFail (LOADINFO_ERROR_CODE_NORMAL );
124126 }
125127 }
126128
@@ -149,7 +151,7 @@ public void run() {
149151 public void onFailure (Call call , IOException e ) {
150152 //获取请求信息失败
151153 if (listener != null ) {
152- listener .onFail (- 1 );
154+ listener .onFail (LOADINFO_ERROR_CODE_NORMAL );
153155 }
154156 }
155157
@@ -162,29 +164,29 @@ public void onResponse(Call call, Response response) throws IOException {
162164 if (code != 200 ) {
163165 String message = jsonObject .getString ("message" );
164166 if (listener != null ) {
165- listener .onFail (- 1 );
167+ listener .onFail (LOADINFO_ERROR_CODE_NORMAL );
166168 }
167169 TXCLog .e (TAG , message );
168170 return ;
169171 }
170172 JSONObject data = jsonObject .getJSONObject ("data" );
171173 JSONArray liveList = data .getJSONArray ("list" );
172174 ArrayList <VideoModel > modelList = new ArrayList <>();
173- for (int i = 0 ; i < liveList .length (); i ++) {
175+ for (int i = 0 ; i < liveList .length (); i ++) {
174176 JSONObject playItem = liveList .getJSONObject (i );
175177 VideoModel model = new VideoModel ();
176- model .appid = playItem .optInt ("appId" ,0 );
177- model .title = playItem .optString ("name" ,"" );
178- model .placeholderImage = playItem .optString ("coverUrl" ,"" );
178+ model .appid = playItem .optInt ("appId" , 0 );
179+ model .title = playItem .optString ("name" , "" );
180+ model .placeholderImage = playItem .optString ("coverUrl" , "" );
179181
180182 JSONArray urlList = playItem .getJSONArray ("playUrl" );
181183 if (urlList .length () > 0 ) {
182184
183185 model .multiVideoURLs = new ArrayList <>(urlList .length ());
184- model .videoURL = urlList .getJSONObject (0 ).optString ("url" ,"" );
185- for (int j = 0 ; j < urlList .length (); j ++) {
186+ model .videoURL = urlList .getJSONObject (0 ).optString ("url" , "" );
187+ for (int j = 0 ; j < urlList .length (); j ++) {
186188 JSONObject urlItem = urlList .getJSONObject (j );
187- model .multiVideoURLs .add (new VideoModel .VideoPlayerURL (urlItem .optString ("title" ,"" ),urlItem .optString ("url" ,"" )));
189+ model .multiVideoURLs .add (new VideoModel .VideoPlayerURL (urlItem .optString ("title" , "" ), urlItem .optString ("url" , "" )));
188190 }
189191 }
190192
@@ -209,29 +211,53 @@ private void parseJson(VideoModel videoModel, String content) {
209211 }
210212 try {
211213 JSONObject jsonObject = new JSONObject (content );
212- int code = jsonObject .getInt ("code" );
213- if (code != 0 ) {
214- String message = jsonObject .getString ("message" );
215- if (mOnVodInfoLoadListener != null ) {
216- mOnVodInfoLoadListener .onFail (-1 );
214+ final int code = jsonObject .getInt ("code" );
215+ final String message = jsonObject .optString ("message" );
216+ final String warning = jsonObject .optString ("warning" );
217+ TXCLog .i (TAG , "message: " + message );
218+ TXCLog .i (TAG , "warning: " + warning );
219+ if (code == 0 ) {
220+ int version = jsonObject .getInt ("version" );
221+ if (version == 2 ) {
222+ PlayInfoResponseParser playInfoResponse = new PlayInfoResponseParser (jsonObject );
223+ videoModel .placeholderImage = playInfoResponse .coverUrl ();
224+
225+ TCPlayInfoStream stream = playInfoResponse .getSource ();
226+ if (stream != null ) {
227+ videoModel .duration = stream .getDuration ();
228+ }
229+ videoModel .title = playInfoResponse .description ();
230+ if (videoModel .title == null || videoModel .title .length () == 0 ) {
231+ videoModel .title = playInfoResponse .name ();
232+ }
233+ if (mOnVodInfoLoadListener != null ) {
234+ mOnVodInfoLoadListener .onSuccess (videoModel );
235+ }
236+ return ;
237+ } else if (version == 4 ) {
238+ JSONObject media = jsonObject .getJSONObject ("media" );
239+ if (media != null ) {
240+ //解析视频名称
241+ JSONObject basicInfo = media .optJSONObject ("basicInfo" );
242+ if (basicInfo != null ) {
243+ videoModel .title = basicInfo .optString ("description" );
244+ if (videoModel .title == null || videoModel .title .length () == 0 ) {
245+ videoModel .title = basicInfo .optString ("name" );
246+ }
247+ videoModel .placeholderImage = basicInfo .optString ("coverUrl" );
248+ videoModel .duration = basicInfo .optInt ("duration" );
249+ }
250+ if (mOnVodInfoLoadListener != null ) {
251+ mOnVodInfoLoadListener .onSuccess (videoModel );
252+ }
253+ return ;
254+ }
217255 }
218- TXCLog .e (TAG , message );
219- return ;
220- }
221- PlayInfoResponseParser playInfoResponse = new PlayInfoResponseParser (jsonObject );
222- videoModel .placeholderImage = playInfoResponse .coverUrl ();
223-
224- TCPlayInfoStream stream = playInfoResponse .getSource ();
225- if (stream != null ) {
226- videoModel .duration = stream .getDuration ();
227- }
228- videoModel .title = playInfoResponse .description ();
229- if (videoModel .title == null || videoModel .title .length () == 0 ) {
230- videoModel .title = playInfoResponse .name ();
231256 }
232257 if (mOnVodInfoLoadListener != null ) {
233- mOnVodInfoLoadListener .onSuccess ( videoModel );
258+ mOnVodInfoLoadListener .onFail ( LOADINFO_ERROR_CODE_NORMAL );
234259 }
260+ return ;
235261 } catch (JSONException e ) {
236262 e .printStackTrace ();
237263 }
0 commit comments