I am trying to develeop a video capture application on the HTC Ion
device using the MediaRecorder class. The application seems to run and
record MP4 output file, but it is blank when I view it with QuickTime!
I am wondering if I am setting up the MediaRecorder correctly.
Also, expected to see a live preview because a Surface to display the
preview was set . But nothing shows up.
Any one have suggestions as to what could be doing wrong? I have
pasted the code below. Thanks in advance!
Sreeram
public class Snapper extends Activity {
public MediaRecorder mrec = null;
private Button startRecording = null;
private Button stopRecording = null;
private SurfaceView surface = null;
private TextView debugText = null;
private static final String TAG = "Video";
File videofile;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mrec = new MediaRecorder();
startRecording = (Button)findViewById(R.id.snap);
stopRecording = (Button)findViewById(R.id.stop);
surface = (SurfaceView) findViewById(R.id.surface);
//mrec.setCamera(Camera.open());
mrec.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mrec.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mrec.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mrec.setPreviewDisplay(surface.getHolder().getSurface());
startRecording.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
try {
startRecording.setEnabled(false);
startRecording();
} catch (Exception e) {
Log.e(TAG,"Caught io exception " + e.getMessage());
}
}
});
stopRecording.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
try {
stopRecording.setEnabled(false);
stopRecording();
} catch (Exception ee) {
Log.e(TAG,"Caught io exception " + ee.getMessage());
}
String file = processvideofile();
uploadFile(file);
}
});
startRecording.setEnabled(true);
}
protected String processvideofile() {
ContentValues values = new ContentValues(4);
long current = System.currentTimeMillis();
values.put(MediaStore.Video.Media.TITLE, "video" +
videofile.getName());
values.put(MediaStore.Video.Media.DATE_ADDED, (int) (current /
1000));
values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
values.put(MediaStore.Video.Media.DATA,
videofile.getAbsolutePath());
ContentResolver contentResolver = getContentResolver();
Uri base = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
Uri newUri = contentResolver.insert(base, values);
return videofile.getName();
}
protected void startRecording() throws IOException
{
if (videofile == null) {
File sampleDir = Environment.getExternalStorageDirectory
();
try {
videofile = File.createTempFile("foo", ".mp4",
sampleDir);
}
catch (IOException e)
{
Log.e(TAG,"sdcard access error");
return;
}
}
mrec.setOutputFile(videofile.getAbsolutePath());
mrec.prepare();
mrec.start();
}
protected void stopRecording() {
mrec.stop();
mrec.release();
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---