Ejemplo n.º 1
0
  /**
   * 获取 XL 云播的 视频列表
   *
   * @param context
   * @param per 一页的个数 >=1
   * @param page 页码 从第一页开始
   * @return
   */
  public static ArrayList<XLLXFileInfo> getVideoList(Context context, int per, int page) {
    try {
      String CookieUID = XLLXBiz.getUserUID(context);
      if (isNumeric(CookieUID) && CookieUID != "-") {
        CookieUID = "userid=" + CookieUID + ";";
      } else {
        CookieUID =
            "userid=" + XLLXBiz.getUID(context) + "; sessionid=" + XLLXBiz.getSessionid(context);
      }
      Log.d(TAG, "CookieUID= " + CookieUID);
      Header cookie = new BasicHeader(XLLXBiz.COOKIE, CookieUID);
      String url =
          "http://i.vod.xunlei.com/req_history_play_list/req_num/"
              + per
              + "/req_offset/"
              + per * (page - 1);

      String json =
          HttpUtils.getContent(
              url,
              new Header[] {cookie},
              new NameValuePair[] {
                new BasicNameValuePair("type", "all"),
                new BasicNameValuePair("order", "create"),
                new BasicNameValuePair("t", String.valueOf(System.currentTimeMillis()))
              });
      if (json == null) {
        return null;
      }
      json = URLDecoder.decode(json);
      Log.d(TAG, "getVideoList  json= " + json);
      JSONTokener jsonParser = new JSONTokener(json);
      JSONObject object = (JSONObject) jsonParser.nextValue();
      JSONObject resp = object.getJSONObject("resp");
      int recodenum = resp.getInt("record_num");
      Log.d(TAG, "getVideoList  record_num= " + recodenum);
      JSONArray history_play_list = resp.getJSONArray("history_play_list");
      ArrayList<XLLXFileInfo> list = new ArrayList<XLLXFileInfo>();
      for (int i = 0; i < history_play_list.length(); i++) {
        XLLXFileInfo info = new XLLXFileInfo();
        JSONObject historyPlay = history_play_list.getJSONObject(i);
        info.file_name = (historyPlay.getString("file_name"));
        info.src_url = (historyPlay.getString("src_url"));
        info.createTime = historyPlay.getString("createtime");
        info.duration = historyPlay.getString("duration");
        info.filesize = historyPlay.getString("file_size");
        info.userid = historyPlay.getString("userid");
        info.urlhash = historyPlay.getString("url_hash");
        info.gcid = historyPlay.getString("gcid");
        info.cid = historyPlay.getString("cid");
        info.recodenum = recodenum;
        if (info.src_url.contains("bt://")) {
          info.isDir = true;
        }
        list.add(info);
      }
      return list;

    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }