예제 #1
0
 @Override
 protected void onPause() {
   super.onPause();
   MyMessageReceiver.ehList.remove(this); // 监听推送的消息
   // 停止录音
   if (recordManager.isRecording()) {
     recordManager.cancelRecording();
     layout_record.setVisibility(View.GONE);
   }
   // 停止播放录音
   if (NewRecordPlayClickListener.isPlaying
       && NewRecordPlayClickListener.currentPlayListener != null) {
     NewRecordPlayClickListener.currentPlayListener.stopPlayRecord();
   }
 }
예제 #2
0
  private void initRecordManager() {
    // 语音相关管理器
    recordManager = BmobRecordManager.getInstance(this);
    // 设置音量大小监听--在这里开发者可以自己实现:当剩余10秒情况下的给用户的提示,类似微信的语音那样
    recordManager.setOnRecordChangeListener(
        new OnRecordChangeListener() {
          @Override
          public void onVolumnChanged(int value) {
            iv_record.setImageDrawable(drawable_Anims[value]);
          }

          @Override
          public void onTimeChanged(int recordTime, String localPath) {
            BmobLog.i("voice", "已录音长度:" + recordTime);
            if (recordTime >= BmobRecordManager.MAX_RECORD_TIME) { // 1分钟结束,发送消息
              // 需要重置按钮
              btn_speak.setPressed(false);
              btn_speak.setClickable(false);
              // 取消录音框
              layout_record.setVisibility(View.INVISIBLE);
              // 发送语音消息
              sendVoiceMessage(localPath, recordTime);
              // 是为了防止过了录音时间后,会多发一条语音出去的情况。
              handler.postDelayed(
                  new Runnable() {

                    @Override
                    public void run() {
                      btn_speak.setClickable(true);
                    }
                  },
                  1000);
            } else {

            }
          }
        });
  }