當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaRecorder.setAudioEncoder方法代碼示例

本文整理匯總了Java中android.media.MediaRecorder.setAudioEncoder方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaRecorder.setAudioEncoder方法的具體用法?Java MediaRecorder.setAudioEncoder怎麽用?Java MediaRecorder.setAudioEncoder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.media.MediaRecorder的用法示例。


在下文中一共展示了MediaRecorder.setAudioEncoder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: 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

示例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: 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

示例4: 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

示例5: 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

示例6: 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

示例7: getRecorder

import android.media.MediaRecorder; //導入方法依賴的package包/類
private void getRecorder() {
    recorder = new MediaRecorder();
    //麥克風
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    //設置格式 3GP
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    //設置保存目錄 權限
    recorder.setOutputFile("sdcard/audio.3gp");
    //設置音頻編碼
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    try {
        //準備錄音
        recorder.prepare();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:wuhighway,項目名稱:DailyStudy,代碼行數:19,代碼來源:MyService.java

示例8: RecordingController

import android.media.MediaRecorder; //導入方法依賴的package包/類
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);
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:18,代碼來源:SoundRecorder.java

示例9: prepare

import android.media.MediaRecorder; //導入方法依賴的package包/類
public void prepare() throws IOException {
    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    mRecorder.setAudioSamplingRate(44100);
    mRecorder.setAudioEncodingBitRate(96000);
    mRecorder.setOutputFile(mFilePath);
    mRecorder.prepare();
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:11,代碼來源:Recorder.java

示例10: initRecord

import android.media.MediaRecorder; //導入方法依賴的package包/類
private void initRecord() {
        try {
            mMediaRecorder = new MediaRecorder();
            mMediaRecorder.reset();
            mMediaRecorder.setCamera(mCamera);
            mMediaRecorder.setOnErrorListener(this);
            mMediaRecorder.setPreviewDisplay(mSurfaceHolder.getSurface());
            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(mWidthPixel, mHeightPixel);//設置分辨率
//        mMediaRecorder.setVideoFrameRate(25);// 設置每秒幀數 這個設置有可能會出問題,有的手機不支持這種幀率就會錄製失敗,這裏使用默認的幀率,當然視頻的大小肯定會受影響
            if (mPictureSize < 3000000) {//這裏設置可以調整清晰度
                mMediaRecorder.setVideoEncodingBitRate(3 * 1024 * 512);
            } else if (mPictureSize <= 5000000) {
                mMediaRecorder.setVideoEncodingBitRate(2 * 1024 * 512);
            } else {
                mMediaRecorder.setVideoEncodingBitRate(1 * 1024 * 512);
            }
            mMediaRecorder.setOrientationHint(90);//輸出旋轉90度,保持豎屏錄製
            mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);//視頻錄製格式
            //mMediaRecorder.setMaxDuration(Constant.MAXVEDIOTIME * 1000);
            mMediaRecorder.setOutputFile(mRecordFile.getAbsolutePath());
            mMediaRecorder.prepare();
        } catch (Exception e) {
            e.printStackTrace();
            releaseCamera();
        }
    }
 
開發者ID:mChenys,項目名稱:AndroidFFmpegCompress,代碼行數:31,代碼來源:RecordView.java

示例11: 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

示例12: 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

示例13: 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

示例14: AudioRecordingAacThread

import android.media.MediaRecorder; //導入方法依賴的package包/類
public AudioRecordingAacThread() {
	try{
		recorder = new MediaRecorder();
		recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
		recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
		// 設置MediaRecorder錄製的音頻格式(不要修改其它格式了,後端對格式做了限定)
		recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
		recorder.setAudioSamplingRate(8000);
	}catch (Exception e){

	}

}
 
開發者ID:lennyup,項目名稱:react-native-udesk,代碼行數:14,代碼來源:AudioRecordingAacThread.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.setAudioEncoder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。