android如何实现视频边录边上传
1个回答
展开全部
/**
* 实时上传到PC端(边录边传)
*
*/
private final class ButtonClickListener1 implements View.OnClickListener
{
@Override
public void onClick(View v)
{
if (!Environment.getExternalStorageState().equals(
Environment.MEDIA_MOUNTED))
{
Toast.makeText(MainActivity.this, R.string.sdcarderror, 1)
.show();
return;
}
try
{
switch (v.getId())
{
case R.id.record:
mediaRecorder.reset();
mediaRecorder
.setVideoSource(MediaRecorder.VideoSource.CAMERA); // 从照相机采集视频
//mediaRecorder
//.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder
.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
mediaRecorder.setVideoSize(480, 320);
mediaRecorder.setVideoFrameRate(3); // 每秒3帧
mediaRecorder
.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT); // 设置视频编码方式
//mediaRecorder
// .setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setPreviewDisplay(surfaceView.getHolder()
.getSurface());
// 实时上传的代码
receiver = new Socket("192.168.1.149", 9999);
ParcelFileDescriptor pfd = ParcelFileDescriptor
.fromSocket(receiver);
mediaRecorder.setOutputFile(pfd.getFileDescriptor());
mediaRecorder.prepare();// 预期准备
mediaRecorder.start();// 开始刻录
record = true;
break;
case R.id.stop:
if (record)
{
System.out.println(videoFile);
mediaRecorder.stop();
mediaRecorder.release();
receiver.close();
record = false;
}
break;
}
} catch (Exception e)
{
Toast.makeText(MainActivity.this, R.string.error, 1).show();
Log.e(TAG, e.toString());
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询