android.media.MediaRecorder#setOnErrorListener ( )源码实例Demo

下面列出了android.media.MediaRecorder#setOnErrorListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: appinventor-extensions   文件: SoundRecorder.java
RecordingController(String savedRecording) throws IOException {
  // pick a pathname if none was specified
  file = (savedRecording.equals("")) ?
      FileUtil.getRecordingFile("3gp").getAbsolutePath() :
        savedRecording;

  recorder = new MediaRecorder();
  recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
  recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
  recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
  Log.i(TAG, "Setting output file to " + file);
  recorder.setOutputFile(file);
  Log.i(TAG, "preparing");
  recorder.prepare();
  recorder.setOnErrorListener(SoundRecorder.this);
  recorder.setOnInfoListener(SoundRecorder.this);
}
 
源代码2 项目: FamilyChat   文件: MediaRecorderSystemImpl.java
@Override
public void initRecorder(Camera camera, int cameraId, Surface surface, String filePath)
{
    mMediaRecorder = new MediaRecorder();
    mMediaRecorder.reset();
    if (camera != null)
        mMediaRecorder.setCamera(camera);
    mMediaRecorder.setOnErrorListener(this);
    mMediaRecorder.setPreviewDisplay(surface);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);//视频源
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);//音频源
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);//视频输出格式 也可设为3gp等其他格式
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);//音频格式
    mMediaRecorder.setVideoSize(640, 480);//设置分辨率,市面上大多数都支持640*480
    //        mediaRecorder.setVideoFrameRate(25);//设置每秒帧数 这个设置有可能会出问题,有的手机不支持这种帧率就会录制失败,这里使用默认的帧率,当然视频的大小肯定会受影响
    //这里设置可以调整清晰度
    mMediaRecorder.setVideoEncodingBitRate(2 * 1024 * 512);

    if (cameraId == Camera.CameraInfo.CAMERA_FACING_BACK)
        mMediaRecorder.setOrientationHint(90);
    else
        mMediaRecorder.setOrientationHint(270);
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);//视频录制格式
    mMediaRecorder.setOutputFile(filePath);
}
 
源代码3 项目: DeviceConnect-Android   文件: StreamingRecorder.java
/**
 * 動画撮影のための準備を行います.
 *
 * @throws IOException 動画撮影の準備に失敗した場合に発生
 */
public synchronized void setUpMediaRecorder(File outputFile) throws IOException {
    if (DEBUG) {
        Log.e(TAG, "Set up MediaRecorder");
        Log.e(TAG, "  VideoSize: " + mSettings.getWidth() + "x" + mSettings.getHeight());
        Log.e(TAG, "  BitRate: " + mSettings.getBitRate());
        Log.e(TAG, "  FrameRate: " + mSettings.getFrameRate());
        Log.e(TAG, "  OutputFile: " + outputFile.getAbsolutePath());
    }

    int rotation = getDisplayRotation();
    mMediaRecorder = new MediaRecorder();
    mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
    mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mMediaRecorder.setOutputFile(outputFile.getAbsolutePath());
    mMediaRecorder.setVideoEncodingBitRate(mSettings.getBitRate());
    mMediaRecorder.setVideoFrameRate(mSettings.getFrameRate());
    mMediaRecorder.setVideoSize(mSettings.getWidth(), mSettings.getHeight());
    mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
    mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    mMediaRecorder.setOrientationHint(ORIENTATIONS[mSettings.getSensorOrientation()].get(rotation));
    mMediaRecorder.setOnInfoListener(mOnInfoListener);
    mMediaRecorder.setOnErrorListener(mOnErrorListener);
    mMediaRecorder.prepare();
}
 
源代码4 项目: GravityBox   文件: RecordingService.java
private void startRecording() {
    String statusMessage = "";
    String audioFileName = prepareOutputFile();
    try {
        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mRecorder.setOutputFile(audioFileName);
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        mRecorder.setAudioEncodingBitRate(96000);
        mRecorder.setAudioSamplingRate(mSamplingRate);
        mRecorder.setOnErrorListener(mOnErrorListener);
        mRecorder.prepare();
        mRecorder.start();
        mRecordingStatus = RECORDING_STATUS_STARTED;
        startForeground(1, mRecordingNotif);
    } catch (Exception e) {
        e.printStackTrace();
        mRecordingStatus = RECORDING_STATUS_ERROR;
        statusMessage = e.getMessage();
    } finally {
        Intent i = new Intent(ACTION_RECORDING_STATUS_CHANGED);
        i.putExtra(EXTRA_RECORDING_STATUS, mRecordingStatus);
        if (mRecordingStatus == RECORDING_STATUS_STARTED) {
            i.putExtra(EXTRA_AUDIO_FILENAME, audioFileName);
        }
        i.putExtra(EXTRA_STATUS_MESSAGE, statusMessage); 
        sendBroadcast(i);
    }
}
 
private void initMediaRecorder() {
    recorder = new MediaRecorder();
    recorder.setAudioSource(configurationBuilder.audioSource);
    recorder.setOutputFormat(configurationBuilder.outputFormat);
    recorder.setOutputFile(configurationBuilder.filePath);
    recorder.setAudioChannels(configurationBuilder.channels);
    recorder.setAudioEncoder(configurationBuilder.audioEncoder);
    recorder.setAudioEncodingBitRate(configurationBuilder.bitRate);
    recorder.setAudioSamplingRate(configurationBuilder.samplingRate);
    recorder.setMaxDuration(configurationBuilder.duration);
    recorder.setOnInfoListener(new OnInfoListenerImpl());
    recorder.setOnErrorListener(new OnErrorListenerImpl());
}
 
public MediaRecorder prepareMediaRecorder() {

        audioRecorder = new MediaRecorder();
        audioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        audioRecorder.setAudioEncodingBitRate(256);
        audioRecorder.setAudioChannels(1);
        audioRecorder.setAudioSamplingRate(44100);
        audioRecorder.setOutputFile(outputFile);
        audioRecorder.setOnInfoListener(this);
        audioRecorder.setOnErrorListener(this);

        return audioRecorder;
    }
 
源代码7 项目: CodenameOne   文件: AndroidRecorder.java
public AndroidRecorder(MediaRecorder recorder) {
    this.recorder = recorder;
    recorder.setOnErrorListener(onErrorListener);
}