1

Xamarin の Mono for Android を使用しています。メディア レコーダーの準備メソッドを呼び出すと、次のエラーが表示されます。

java.io.IOException: 準備に失敗しました。

これが私のコードです:

record.Click += delegate {
            try {



                path = Android.OS.Environment.ExternalStorageDirectory.Name + "/" + etVideoName.Text + ".mp4";
                video.StopPlayback ();

                recorder = new MediaRecorder ();
                recorder.SetVideoSource (VideoSource.Camera); 
                recorder.SetAudioSource (AudioSource.Mic);              
                recorder.SetOutputFormat (OutputFormat.Mpeg4);
                recorder.SetVideoEncoder (VideoEncoder.Default); 
                recorder.SetAudioEncoder (AudioEncoder.Default);      
                recorder.SetOutputFile (path);       
                //recorder.SetPreviewDisplay (video.Holder.Surface);         
                recorder.Prepare ();
                recorder.Start ();   
            } catch (Exception ex) {
                MakeAlert("Error", ex.ToString());
            }
        };
4

1 に答える 1

0

これはレコーダーです 100% 仕事です 勉強してください :)

   package com.camara.activity;

   import java.io.IOException;

   import android.content.Context;
   import android.hardware.Camera;
   import android.media.MediaRecorder;
   import android.util.AttributeSet;
   import android.util.Log;
   import android.view.SurfaceHolder;
   import android.view.SurfaceView;

public class CamcorderView extends SurfaceView implements
    SurfaceHolder.Callback {

MediaRecorder recorder;
SurfaceHolder holder;
String outputFile = "/sdcard/default.mp4";

public CamcorderView(Context context, AttributeSet attrs) {
    super(context, attrs);

    holder = getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    recorder = new MediaRecorder();
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setVideoEncoder(MediaRecorder.VideoEncoder.MPEG_4_SP);
    recorder.setVideoSize(480, 320);
    recorder.setVideoFrameRate(10);
    recorder.setMaxDuration(10000);

}

public void surfaceCreated(SurfaceHolder holder) {

    recorder.setOutputFile(outputFile);
    recorder.setPreviewDisplay(holder.getSurface());
    if (recorder != null) {
        try {
            recorder.prepare();

        } catch (IllegalStateException e) {
            Log.e("IllegalStateException", e.toString());
        } catch (IOException e) {
            Log.e("IOException", e.toString());
        }
    }
}

public void surfaceChanged(SurfaceHolder holder, int format, int width,
        int height) {
}

public void surfaceDestroyed(SurfaceHolder holder) {
}

public void setOutputFile(String filename) {
    outputFile = filename;
    recorder.setOutputFile(filename);
}

  public void startRecording() {
      recorder.start();
 }

   public void stopRecording() {
      recorder.stop();
       recorder.release();



    }

   }
于 2013-06-30T23:56:27.503 に答える