当前位置: 首页>>代码示例>>Java>>正文


Java MediaRecorder.start方法代码示例

本文整理汇总了Java中android.media.MediaRecorder.start方法的典型用法代码示例。如果您正苦于以下问题:Java MediaRecorder.start方法的具体用法?Java MediaRecorder.start怎么用?Java MediaRecorder.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.media.MediaRecorder的用法示例。


在下文中一共展示了MediaRecorder.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: startRecording

import android.media.MediaRecorder; //导入方法依赖的package包/类
public void startRecording() {
    setFileNameAndPath();

    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mRecorder.setOutputFile(mFilePath);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    mRecorder.setAudioChannels(1);
    mRecorder.setAudioSamplingRate(44100);
    mRecorder.setAudioEncodingBitRate(192000);

    try {
        mRecorder.prepare();
        mRecorder.start();
        mStartingTimeMillis = System.currentTimeMillis();
    } catch (IOException e) {
        Log.e(LOG_TAG, "prepare() failed");
    }
}
 
开发者ID:AndroidBoySC,项目名称:Mybilibili,代码行数:21,代码来源:RecordingService.java

示例2: startRecording

import android.media.MediaRecorder; //导入方法依赖的package包/类
public static void startRecording(Context context, MediaRecorder recorder, String word) {
    recorder.reset();
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    recorder.setMaxDuration(10000);
    recorder.setAudioSamplingRate(16000);
    recorder.setAudioEncodingBitRate(16000*4*1);
    recorder.setAudioSamplingRate(44100);
    recorder.setAudioChannels(1);
    recorder.setOutputFile(context.getFilesDir().getAbsolutePath() + "/" + word + ".aac");
    try {
        recorder.prepare();
    } catch (IOException e) {
        e.printStackTrace();
    }
    recorder.start();
}
 
开发者ID:Cesarsk,项目名称:Say_it,代码行数:19,代码来源:UtilityRecordings.java

示例3: recordAudio

import android.media.MediaRecorder; //导入方法依赖的package包/类
static Audio recordAudio(UQI uqi, long duration) throws IOException {
    List<Integer> amplitudes = new ArrayList<>();

    MediaRecorder recorder = new MediaRecorder();
    recorder.setAudioSource(Globals.AudioConfig.audioSource);
    recorder.setOutputFormat(Globals.AudioConfig.outputFormat);
    recorder.setAudioEncoder(Globals.AudioConfig.audioEncoder);

    String audioPath = "temp/audio_" + TimeUtils.getTimeTag() + ".amr";
    File tempAudioFile = StorageUtils.getValidFile(uqi.getContext(), audioPath, false);
    recorder.setOutputFile(tempAudioFile.getAbsolutePath());

    recorder.prepare();
    recorder.start();   // Recording is now started

    long startTime = System.currentTimeMillis();
    while (true) {
        long currentTime = System.currentTimeMillis();
        if (currentTime - startTime > duration) {
            break;
        }
        amplitudes.add(recorder.getMaxAmplitude());
    }

    recorder.stop();
    recorder.reset();   // You can reuse the object by going back to setAudioSource() step
    recorder.release(); // Now the object cannot be reused

    AudioData audioData = AudioData.newTempRecord(tempAudioFile, amplitudes);

    return new Audio(startTime, audioData);
}
 
开发者ID:PrivacyStreams,项目名称:PrivacyStreams,代码行数:33,代码来源:AudioRecorder.java

示例4: startRecording

import android.media.MediaRecorder; //导入方法依赖的package包/类
public void startRecording() {
    if (this.paras.isTonghualuyin()) {
        try {
            mediaRecorder = new MediaRecorder();
            mediaRecorder.setAudioSource(4);
            mediaRecorder.setAudioSamplingRate(16000);
            mediaRecorder.setOutputFormat(3);
            mediaRecorder.setAudioEncoder(1);
            mediaRecorder.setOutputFile(this.file.getAbsolutePath());
            mediaRecorder.prepare();
            mediaRecorder.start();
            this.isRecord = true;
        } catch (Exception e) {
            this.isRecord = false;
            mediaRecorder.reset();
            mediaRecorder.release();
            mediaRecorder = null;
        }
    }
}
 
开发者ID:JamesLiAndroid,项目名称:AndroidKillerService,代码行数:21,代码来源:PhoneService.java

示例5: initMediaRecorder

import android.media.MediaRecorder; //导入方法依赖的package包/类
private void initMediaRecorder() {
    try {
        mediaRecorder = new MediaRecorder();
        mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
        mediaRecorder.setAudioSamplingRate(44100);
        mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        mediaRecorder.setAudioEncodingBitRate(96000);
        Date currentTime = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
        fileName = dateFormat.format(currentTime) + ".m4a";
        File audioFile = new File(getCacheDir().getAbsolutePath() + "/" + fileName);  // FIXED: 路径待确定
        Log.i("nib", audioFile.getAbsolutePath());
        mediaRecorder.setOutputFile(audioFile.getAbsolutePath());
        mediaRecorder.prepare();
        mediaRecorder.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:hgs1217,项目名称:Paper-Melody,代码行数:21,代码来源:PlayActivity.java

示例6: startRecorderInternal

import android.media.MediaRecorder; //导入方法依赖的package包/类
private boolean startRecorderInternal() throws Exception {
    shutdownCamera();
    if (!initCamera())
        return false;

    switchCamera.setVisibility(View.GONE);
    mediaRecorder = new MediaRecorder();

    camera.unlock();
    mediaRecorder.setCamera(camera);
    mediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);

    setCamcorderProfile();

    mediaRecorder.setPreviewDisplay(surfaceHolder.getSurface());
    mediaRecorder.setMaxDuration(1000 * VIDEO_TIMES);
    mediaRecorder.setOutputFile(filename);
    setVideoOrientation();

    mediaRecorder.prepare();
    mediaRecorder.start();

    return true;
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:26,代码来源:CaptureVideoActivity.java

示例7: startRecording

import android.media.MediaRecorder; //导入方法依赖的package包/类
private void startRecording() {
    audioRec = new MediaRecorder();
    audioRec.setAudioSource(MediaRecorder.AudioSource.MIC);
    audioRec.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    audioRec.setOutputFile(audioFilePath);
    audioRec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    audioRec.setAudioSamplingRate(256);
    try {
        audioRec.prepare();
        audioRec.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:gvsucis,项目名称:mobile-app-dev-book,代码行数:15,代码来源:AudioActivity.java

示例8: startRecording

import android.media.MediaRecorder; //导入方法依赖的package包/类
public void startRecording() {

        setFileNameAndPath();

        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mRecorder.setOutputFile(mFilePath);
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);

        try {
            mRecorder.prepare();
            mRecorder.start();
            mStartingTimeMillis = System.currentTimeMillis();

            //startTimer();
            //startForeground(1, createNotification());

        } catch (IOException e) {
            Log.e(LOG_TAG, "prepare() failed");
        }
    }
 
开发者ID:tortuvshin,项目名称:health,代码行数:23,代码来源:RecordingService.java

示例9: startRecording

import android.media.MediaRecorder; //导入方法依赖的package包/类
private void startRecording() {

        TransitionManager.beginDelayedTransition(mContainer);

        mFab.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.icon_stop_fab_mini));
        mFab.setSize(FloatingActionButton.SIZE_MINI);

        RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) mFab.getLayoutParams();
        lp.addRule(RelativeLayout.CENTER_HORIZONTAL, 0);    //Same as lp.removeRule(...) only this call is supported from API 17 :(
        lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 1);
        lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 1);
        mFab.setLayoutParams(lp);

        mTapToStartRecording.setVisibility(View.GONE);
        mRecordTime.setVisibility(View.VISIBLE);
        mVisualizer.setVisibility(View.VISIBLE);
        mRecIcon.setVisibility(View.VISIBLE);


        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        mRecorder.setOutputFile(mAudioFilePath);
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

        try {
            mRecorder.prepare();
        } catch (IOException e) {
            Log.e(TAG, "prepare() failed");
        }

        mRecorder.start();
        mVizHandler.post(updateVisualizer);
        startTime = SystemClock.uptimeMillis();
        mTextHandler.postDelayed(updateTime, REPEAT_INTERVAL_TIME);
    }
 
开发者ID:abicelis,项目名称:Remindy,代码行数:37,代码来源:RecordAudioDialogFragment.java

示例10: startRecording

import android.media.MediaRecorder; //导入方法依赖的package包/类
private void startRecording() {
    releaseRecorder();

    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

    mRecordFileOutput = getAudioFilename();

    //TODO: check disk space left?
    mRecorder.setOutputFile(mRecordFileOutput.getPath());
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    try {
        mRecorder.prepare();
    } catch(IOException e) {
        releaseRecorder();
        //TODO: show popup for failure?
        Log.e(TAG, e.toString());
        return;
    }

    mRecorder.start();
    mIsRecording = true;

    //UI update
    chronometer.setBase(SystemClock.elapsedRealtime());
    chronometer.start();

    filenameTxt.setText(mRecordFileOutput.getName());
    imageMic.setImageDrawable(drawable_mic_on);
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:33,代码来源:AudioRecorderActivity.java

示例11: doInBackground

import android.media.MediaRecorder; //导入方法依赖的package包/类
@Override
  protected String doInBackground(String... params) {     
   	MediaRecorder recorder = new MediaRecorder();;

  SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm");
       String currentDateandTime = sdf.format(new Date());
       
       String filename =currentDateandTime + ".3gp";

       File diretory = new File(PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getString("File", "") + File.separator + "Audio");
       diretory.mkdirs();
    	File outputFile = new File(diretory, filename);
       
     recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
     recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
     recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
     recorder.setMaxDuration(Integer.parseInt(i));
     recorder.setMaxFileSize(1000000);
     recorder.setOutputFile(outputFile.toString());

 try 
    {
       recorder.prepare();
       recorder.start();
    } catch (IOException e) {
       Log.i("com.connect", "io problems while preparing");
      e.printStackTrace();
    }		   
return "Executed";
  }
 
开发者ID:mwsrc,项目名称:Dendroid-HTTP-RAT,代码行数:31,代码来源:MyService.java

示例12: startRecording

import android.media.MediaRecorder; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:WrBug,项目名称:GravityBox,代码行数:31,代码来源:RecordingService.java

示例13: onRecordClick

import android.media.MediaRecorder; //导入方法依赖的package包/类
public void onRecordClick(View v) {
    if (!mRecording) {
        File f = new File(getExternalFilesDir(null), "recording.mp4");

        mRecorder = new MediaRecorder();
        mRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        mRecorder.setOutputFile(f.getAbsolutePath());
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC_ELD);
        mRecorder.setAudioSamplingRate(48000);
        mRecorder.setAudioEncodingBitRate(96000);

        try {
            mRecorder.prepare();
        } catch (IOException e) {
            Log.e(TAG, "unable to prepare MediaRecorder");
            mRecorder = null;
            return;
        }

        mRecorder.start();
        mRecording = true;

        setState(STATE_RECORDING);
    } else {
        mRecorder.stop();
        mRecorder.release();
        mRecording = false;

        setState(STATE_IDLE);
    }
}
 
开发者ID:nasa,项目名称:astrobee_android,代码行数:33,代码来源:MainActivity.java

示例14: startRecording

import android.media.MediaRecorder; //导入方法依赖的package包/类
public void startRecording() {
    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    String filePath = FileUtils.createFile(mFileFullName);
    mRecorder.setOutputFile(filePath);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    try {
        mRecorder.prepare();
        mRecorder.start();
    } catch (Exception e) {
        Log.e(TAG, "prepare() failed");
    }
}
 
开发者ID:WorldBank-Transport,项目名称:RoadLab-Pro,代码行数:15,代码来源:VoiceRecordPlayer.java

示例15: prepareAudio

import android.media.MediaRecorder; //导入方法依赖的package包/类
public void prepareAudio() {
    try {
        // 一开始应该是false的
        isPrepared = false;

        File dir = new File(mDirString);
        if (!dir.exists()) {
            dir.mkdirs();
        }

        String fileNameString = generalFileName();
        File file = new File(dir, fileNameString);

        mCurrentFilePathString = file.getAbsolutePath();

        mRecorder = new MediaRecorder();
        // 设置输出文件
        mRecorder.setOutputFile(file.getAbsolutePath());
        // 设置mediaRecorder的音频源是麦克风
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        // 设置文件音频的输出格式为amr
        mRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
        // 设置音频的编码格式为amr
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

        // 严格遵守google官方api给出的mediaRecorder的状态流程图
        mRecorder.prepare();

        mRecorder.start();
        // 准备结束
        isPrepared = true;
        // 已经准备好了,可以录制了
        if (mListener != null) {
            mListener.wellPrepared();
        }

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}
 
开发者ID:Zyj163,项目名称:yyox,代码行数:43,代码来源:AudioManager.java


注:本文中的android.media.MediaRecorder.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。