Пример #1
0
 public void run() {
   try {
     handler_.handleEvent(event_);
   } catch (Throwable t) {
     t.printStackTrace();
   }
 }
  /**
   * Call back function, implement for com.mediatek.dlna.jar. Application should not use this API.
   *
   * @return.
   */
  public void notifyDeviceFound(FoundDeviceEvent event) {
    if (localLOGV) NetLog.d(TAG, "notifyDeviceFound");
    DLNADevice device = event.getDevice();
    String name = device.getName();

    DLNAFile devicefile = new DLNAFile(device, mRoot, mRoot);

    if (localLOGV) NetLog.d(TAG, "add device to device list");
    mListDLNADeviceName.add(devicefile);

    mNameDeviceTable.put(name, device);
    if (listener != null) {
      listener.onFileFound(new FileEvent(event, mListDLNADeviceName));
    }
  }
  /**
   * Call back function, implement for com.mediatek.dlna.jar. Application should not use this API.
   *
   * @return.
   */
  public void notifyDeviceLeft(LeftDeviceEvent event) {
    if (localLOGV) NetLog.d(TAG, "notifyDeviceLeft");
    String name = event.getDevice().getName();
    DLNADevice device = event.getDevice();

    int number = mListDLNADeviceName.size();
    for (int i = 0; i < number; i++) {
      DLNAFile tempDevice = mListDLNADeviceName.get(i);
      if (device.equals(tempDevice.getDevice())) {
        mListDLNADeviceName.remove(tempDevice);
        break;
      }
    }

    mNameDeviceTable.remove(name);
    if (listener != null) {
      listener.onFileLeft(new FileEvent(event, mListDLNADeviceName));
    }
  }
 /**
  * Call back function, implement for com.mediatek.dlna.jar. Application should not use this API.
  *
  * @return.
  */
 public void notifyContentFailed(FailedContentEvent event) {
   if (localLOGV) NetLog.d(TAG, "notifyContentFailed");
   if (listener != null) {
     listener.onFileFailed(new FileEvent(event));
   }
 }
  /**
   * Call back function, implement for com.mediatek.dlna.jar. Application should not use this API.
   *
   * @return.
   */
  public void notifyContentSuccessful(NormalContentEvent event) {

    if (localLOGV) NetLog.v(TAG, " notifyContentSuccessful : " + System.currentTimeMillis());

    if (event == null) {
      if (listener != null) {
        listener.onFileFound(new FileEvent(event, mListContentName));
      }
      return;
    }
    if (event.getTotalMatches() <= 0) {
      if (listener != null) {
        listener.onFileFound(new FileEvent(event, mListContentName));
      }
      return;
    }
    int listnum = event.getList().size();
    if (localLOGV)
      NetLog.v(TAG, " Last index is : " + REQUEST_MATCH_NUM + ", List num is: " + listnum);

    if (listnum <= 0) {
      if (localLOGV) NetLog.v(TAG, " List num is 0, return!");
      if (listener != null) {
        listener.onFileFound(new FileEvent(event, mListContentName));
      }
      return;
    }

    REQUEST_MATCH_NUM = REQUEST_MATCH_NUM + listnum;
    ArrayList<Content> items = event.getList();
    for (int i = 0; i < items.size(); i++) {
      Content cnt = items.get(i);
      String parent = null;
      String cname = cnt.getTitle();
      String tempParent = mCurPath;

      int index = tempParent.lastIndexOf("/");
      if (index == 0) {
        parent = mCurPath.substring(1, mCurPath.length());
      } else {
        parent = mCurPath.substring(index + 1, mCurPath.length());
      }

      StringBuffer pathBuf = new StringBuffer();
      pathBuf.append(mCurPath).append('/').append(cname);

      DLNAFile contentfile = new DLNAFile(cnt, pathBuf.toString(), parent);

      mListContentName.add(contentfile);

      mNameContentTable.put(cname, cnt);
    }
    // LinkedList<DLNAFile> cntList = new LinkedList<DLNAFile>();
    // int size = mNameContentTable.size();
    // for (int i = 0; i < size; i++)
    // cntList.add(mNameContentTable.get(mListContentName.get(i)));
    if (listener != null) {
      listener.onFileFound(new FileEvent(event, mListContentName));
    }

    if (localLOGV) NetLog.v(TAG, " notifyContentSuccessful end : " + System.currentTimeMillis());

    int total = event.getTotalMatches();
    mTotalNum = total;
    if (localLOGV)
      NetLog.v(TAG, " Current index is : " + REQUEST_MATCH_NUM + ", Total is: " + total);
    if (REQUEST_MATCH_NUM < total) {
      mBrowseHandle =
          server.browse(
              currentID,
              MediaServer.BrowseFlag.BrowseDirectChildren,
              REQUEST_MATCH_NUM,
              BROWSE_REQUEST,
              MediaServer.FILTER_BASIC_INFO,
              MediaServer.SORT_ASCENDING_CRITERIA_TITLE);
    }
  }
 private void notifyDirect() {
   FoundDeviceEvent event = null;
   if (listener != null) {
     listener.onFileFound(new FileEvent(event, mListDLNADeviceName));
   }
 }