Exemple #1
0
  /** @Description 录音超时(60s),发消息调用该方法 */
  public void doFinishRecordAudio() {
    try {
      if (audioRecorderInstance.isRecording()) {
        audioRecorderInstance.setRecording(false);
      }
      if (soundVolumeDialog.isShowing()) {
        soundVolumeDialog.dismiss();
      }

      recordAudioBtn.setBackgroundResource(R.drawable.tt_pannel_btn_voiceforward_normal);

      audioRecorderInstance.setRecordTime(SysConstant.MAX_SOUND_RECORD_TIME);
      onRecordVoiceEnd(SysConstant.MAX_SOUND_RECORD_TIME);
    } catch (Exception e) {
    }
  }
Exemple #2
0
  // 主要是录制语音的
  @Override
  public boolean onTouch(View v, MotionEvent event) {
    int id = v.getId();
    scrollToBottomListItem();
    if (id == R.id.record_voice_btn) {
      if (event.getAction() == MotionEvent.ACTION_DOWN) {

        if (AudioPlayerHandler.getInstance().isPlaying())
          AudioPlayerHandler.getInstance().stopPlayer();
        y1 = event.getY();
        recordAudioBtn.setBackgroundResource(R.drawable.tt_pannel_btn_voiceforward_pressed);
        recordAudioBtn.setText(
            MessageActivity.this.getResources().getString(R.string.release_to_send_voice));

        soundVolumeImg.setImageResource(R.drawable.tt_sound_volume_01);
        soundVolumeImg.setVisibility(View.VISIBLE);
        soundVolumeLayout.setBackgroundResource(R.drawable.tt_sound_volume_default_bk);
        soundVolumeDialog.show();
        audioSavePath = CommonUtil.getAudioSavePath(IMLoginManager.instance().getLoginId());

        // 这个callback很蛋疼,发送消息从MotionEvent.ACTION_UP 判断
        audioRecorderInstance = new AudioRecordHandler(audioSavePath);

        audioRecorderThread = new Thread(audioRecorderInstance);
        audioRecorderInstance.setRecording(true);
        logger.d("message_activity#audio#audio record thread starts");
        audioRecorderThread.start();
      } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
        y2 = event.getY();
        if (y1 - y2 > 180) {
          soundVolumeImg.setVisibility(View.GONE);
          soundVolumeLayout.setBackgroundResource(R.drawable.tt_sound_volume_cancel_bk);
        } else {
          soundVolumeImg.setVisibility(View.VISIBLE);
          soundVolumeLayout.setBackgroundResource(R.drawable.tt_sound_volume_default_bk);
        }
      } else if (event.getAction() == MotionEvent.ACTION_UP) {
        y2 = event.getY();
        if (audioRecorderInstance.isRecording()) {
          audioRecorderInstance.setRecording(false);
        }
        if (soundVolumeDialog.isShowing()) {
          soundVolumeDialog.dismiss();
        }
        recordAudioBtn.setBackgroundResource(R.drawable.tt_pannel_btn_voiceforward_normal);
        recordAudioBtn.setText(
            MessageActivity.this.getResources().getString(R.string.tip_for_voice_forward));
        if (y1 - y2 <= 180) {
          if (audioRecorderInstance.getRecordTime() >= 0.5) {
            if (audioRecorderInstance.getRecordTime() < SysConstant.MAX_SOUND_RECORD_TIME) {
              Message msg = uiHandler.obtainMessage();
              msg.what = HandlerConstant.HANDLER_RECORD_FINISHED;
              msg.obj = audioRecorderInstance.getRecordTime();
              uiHandler.sendMessage(msg);
            }
          } else {
            soundVolumeImg.setVisibility(View.GONE);
            soundVolumeLayout.setBackgroundResource(R.drawable.tt_sound_volume_short_tip_bk);
            soundVolumeDialog.show();
            Timer timer = new Timer();
            timer.schedule(
                new TimerTask() {
                  public void run() {
                    if (soundVolumeDialog.isShowing()) soundVolumeDialog.dismiss();
                    this.cancel();
                  }
                },
                700);
          }
        }
      }
    }
    return false;
  }