コード例 #1
0
  @Override
  protected void modifyMainAttach() {
    if (isDiaryMontaged) {
      String inputFile = mainAudioPath;
      long currentTime = TimeHelper.getInstance().now();
      String voiceID = String.valueOf(currentTime);
      String RECORD_FILE_DIR =
          Constant.SD_STORAGE_ROOT
              + "/"
              + ActiveAccount.getInstance(this).getLookLookID()
              + "/audio";
      String outputFile =
          Environment.getExternalStorageDirectory()
              + RECORD_FILE_DIR
              + "/"
              + voiceID
              + "/"
              + voiceID
              + ".mp4";

      File dstFile = new File(outputFile);
      if (!dstFile.getParentFile().exists()) {
        dstFile.getParentFile().mkdirs();
      }
      editAttachPath = outputFile;
      montageAudio(voiceID, inputFile, outputFile); // 1s
    }

    if (mEffects.getEffectsCount() > 0) {
      try {

        String infilename = "";
        if (editAttachPath != null) {
          infilename = editAttachPath;
        } else {
          infilename = mainAudioPath;
        }
        Log.d(TAG, "infilename = " + infilename);
        EffectTransCodeUtil transCode =
            new EffectTransCodeUtil(
                handler, mEffects, infilename, this, EffectTransCodeUtil.MAIN_AUDIO);
        transCode.start("audio");
        threadsSignal = new CountDownLatch(1);
        threadsSignal.await();

        if (effectAudioPath != null) {
          if (editAttachPath != null) {
            EditMediaDetailActivity.delFile(editAttachPath);
          }
          editAttachPath = effectAudioPath;
        }

        Log.d(TAG, "editAttachPath = " + editAttachPath + " effectAudioPath = " + effectAudioPath);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
コード例 #2
0
  @Override
  protected void copyMainAttach() {
    // TODO Auto-generated method stub
    if (mainAudioPath == null) {
      return;
    }
    String audioID = String.valueOf(TimeHelper.getInstance().now());
    String dstFilePath =
        Environment.getExternalStorageDirectory().getPath()
            + Constant.SD_STORAGE_ROOT
            + "/"
            + ActiveAccount.getInstance(this).getLookLookID()
            + "/audio/"
            + audioID
            + "/"
            + audioID
            + ".mp4";

    long fileLength = copyFile2(mainAudioPath, dstFilePath);
    if (fileLength > 0) {
      editAttachPath = dstFilePath;
    }
  }
コード例 #3
0
ファイル: CacheNetworkTask.java プロジェクト: nabolen/WeFlow
  @Override
  public boolean handleMessage(Message msg) {

    switch (msg.what) {
      case STATE_WAITING:
        Log.d("debug", "I am waiting!");
        break;

      case STATE_PREPARING:
        // 网络状态判断
        if (ZNetworkStateDetector.isAvailable()
            && ZNetworkStateDetector.isConnected()
            && this.info != null
            && this.info.upRequest != null) {
          // 请求日记结构
          Requester3.createStructure(
              handler,
              this.info.upRequest.diaryid,
              this.info.upRequest.diaryuuid,
              this.info.upRequest.operate_diarytype,
              this.info.upRequest.resourcediaryid,
              this.info.upRequest.resourcediaryuuid,
              this.info.upRequest.tags,
              String.valueOf(TimeHelper.getInstance().now()),
              this.info.upRequest.addresscode,
              this.info.upRequest.position_status,
              this.info.upRequest.isonlymic,
              this.info.upRequest.longitude_real,
              this.info.upRequest.latitude_real,
              this.info.upRequest.position_real,
              this.info.upRequest.longitude,
              this.info.upRequest.latitude,
              this.info.upRequest.position,
              this.info.upRequest.longitude_view,
              this.info.upRequest.latitude_view,
              this.info.upRequest.position_view,
              this.info.upRequest.shoottime,
              this.info.upRequest.attachs);
        } else {
          //				Toast.makeText(ZApplication.getInstance().getApplicationContext(), "网络异常,无法启动该任务!",
          // Toast.LENGTH_LONG).show();
          translateToState(STATE_ERROR);
        }
        break;

      case Requester3.RESPONSE_TYPE_CREATE_STRUCTURE:
        GsonResponse3.createStructureResponse response =
            (GsonResponse3.createStructureResponse) msg.obj;
        if (msg.obj != null
            && response != null
            && response.attachs != null
            && response.status.equals("0")) {
          this.info.diaryid = response.diaryid; // 取得diaryid
          DiaryManager diarymanager = DiaryManager.getInstance();
          MyDiary myLocalDiary = diarymanager.findMyDiaryByUUID(response.diaryuuid);
          MyDiaryList diarylist = diarymanager.findDiaryGroupByUUID(response.diaryuuid);
          if (myLocalDiary != null && diarylist != null) {
            myLocalDiary.diaryid = response.diaryid;
            myLocalDiary.sync_status = 1;
            Log.d(TAG, "diaryid = " + myLocalDiary.diaryid);
            diarylist.diaryid = response.diaryid;
          } else if (this.info.source != 1) {
            Log.d(TAG, "Should Not Be Here!");
            translateToState(STATE_REMOVED);
            return false;
          }

          if (this.info == null
              || this.info.caMedias == null /*|| this.info.caMedias.size() <= 0*/) {
            Log.e(TAG, "Do not click the control button rapidly!");
            return false;
          }

          for (int i = 0; i < response.attachs.length; i++) {
            for (int j = 0; j < this.info.caMedias.size(); j++) {
              Log.d(TAG, "caMedias size = " + this.info.caMedias.size() + "i = " + i + ",j = " + j);
              upMedia tmpmedia = this.info.caMedias.get(j);
              if (tmpmedia == null) {
                Log.d(TAG, "tmpmedia is null");
              }
              if (response.attachs[i] != null
                  && tmpmedia.attachuuid.equals(response.attachs[i].attachuuid)) {
                this.info.caMedias.get(j).attachid = response.attachs[i].attachid; // 取得attachid

                // tmpmf.remotepath = response.attachs[i].path;
                for (int k = 0; k < this.info.caMedias.get(j).attachMedia.size(); k++) {
                  String remoteUrl = this.info.caMedias.get(j).attachMedia.get(k).remotepath;
                  this.info.caMedias.get(j).attachMedia.get(k).remotepath =
                      response.attachs[i].path; // 取得服务器地址
                  // 写入mapping
                  if (response.attachs[i].path != null) {
                    MediaValue tmMV = new MediaValue();
                    tmMV =
                        AccountInfo.getInstance(this.info.userid)
                            .mediamapping
                            .getMedia(this.info.userid, remoteUrl);
                    if (tmMV != null) {
                      Log.d(TAG, "get MediaValue.url=" + tmMV.url);
                      tmMV.url = response.attachs[i].path;
                      AccountInfo.getInstance(this.info.userid)
                          .mediamapping
                          .setMedia(this.info.userid, response.attachs[i].path, tmMV);
                      AccountInfo.getInstance(this.info.userid)
                          .mediamapping
                          .delMedia(this.info.userid, remoteUrl);
                      Log.d(TAG, "set MediaValue.url=" + tmMV.url);
                    }
                  }
                }
              }
            }
            if (this.info.source != 1) {
              // 修改日记结构
              if (myLocalDiary != null && myLocalDiary.attachs != null) {
                DiaryAttach diaryattach = myLocalDiary.attachs;
                // 主
                MainAttach mainattach = diaryattach.levelattach;
                if (mainattach != null) {
                  if (mainattach.attachuuid.equals(response.attachs[i].attachuuid)) {
                    mainattach.attachid = response.attachs[i].attachid;
                    mainattach.attachurl = response.attachs[i].path;
                  }
                }
                // 辅
                AuxAttach[] auxattach = diaryattach.attach;
                if (auxattach != null) {
                  for (int k = 0; k < auxattach.length; k++) {
                    if (auxattach[k].attachuuid.equals(response.attachs[i].attachuuid)) {
                      auxattach[k].attachid = response.attachs[i].attachid;
                      auxattach[k].attachurl = response.attachs[i].path;
                    }
                  }
                }
              }
            }
          }
          if (this.info.source != 1) DiaryManager.getInstance().notifyMyDiaryChanged();

          // 转变正常上传任务
          translateToState(STATE_COMPELETED);
        } else {
          translateToState(ACTION_RETRY);
          return false;
        }
        break;

        // 转变正常上传任务
      case STATE_RUNNING:
        retryTimes = 0;
        break;

      case STATE_PAUSED:
        retryTimes = 0;
        stopThread();
        break;

      case STATE_REMOVED:
        retryTimes = 0;
        stopThread();
        if (taskmanagerListener != null) {
          taskmanagerListener.OnTaskRemoved(this);
        }
        if (mitaskmanagerListener != null) {
          mitaskmanagerListener.OnTaskRemoved(this);
        }
        break;

      case ACTION_RETRY:
        if (retryTimes < 2) {
          retryTimes++;
          ZThread.sleep(500); // 500, 2000, 3500, 5000
          if (getState() == STATE_PAUSED) {
            ZLog.e("Status changed to [" + getState() + "] when retrying!");
            translateToState(STATE_PAUSED);
            break;
          } else if (getState() == STATE_WAITING) {
            ZLog.e("Status changed to [" + getState() + "] when retrying, ignore it!");
            break;
          }
          translateToState(STATE_PREPARING);
          // return是为了不执行 notifyStateChange
          return false;
        } else {
          translateToState(STATE_ERROR);
        }
        break;

        // 转变正常上传任务
      case STATE_COMPELETED:
        retryTimes = 0;
        stopThread();
        Log.d(TAG, "离线任务成功转换成上传任务");
        break;

      case STATE_ERROR:
        break;
    }

    return false;
  }