关于自动录制视频的功能

ice_blue_coffee 2014-12-16 03:50:35
我想实现打开app就马上录制视频,但是运行的时候总会出现

E/MediaRecorderJNI﹕ Application lost the surface
12-16 15:49:43.659 28394-28394/com.jinglingtec.ijiazu E/MyRcoder﹕ invalid preview surface
12-16 15:49:43.749 28394-28394/com.jinglingtec.ijiazu E/MediaRecorderJNI﹕ Application lost the surface
12-16 15:49:43.749 28394-28394/com.jinglingtec.ijiazu E/MyRcoder﹕ invalid preview surface

的错误;

@Override
public void onCreate(Bundle savedInstanceState)
{


super.onCreate(savedInstanceState);
// 去掉标题栏 ,必须放在setContentView之前
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.video_record);
// 设置横屏显示
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
// 设置全屏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// 选择支持半透明模式,在有surfaceview的activity中使用。
getWindow().setFormat(PixelFormat.TRANSLUCENT);

// 获取程序界面中的SurfaceView
sView = (SurfaceView) this.findViewById(R.id.sView);
// 设置分辨率
sView.getHolder().setFixedSize(1280, 720);
// 设置该组件让屏幕不会自动关闭
sView.getHolder().setKeepScreenOn(true);

try
{
// 创建保存录制视频的视频文件
videoFile = new File(Environment
.getExternalStorageDirectory()
.getCanonicalFile() + "/testvideo.3gp");

String str = videoFile.getPath();
Log.e("MyRcoder", str);
// 创建MediaPlayer对象
mRecorder = new MediaRecorder();
mRecorder.reset();
// 设置从麦克风采集声音(或来自录像机的声音AudioSource.CAMCORDER)
mRecorder.setAudioSource(MediaRecorder
.AudioSource.MIC);
// 设置从摄像头采集图像
mRecorder.setVideoSource(MediaRecorder
.VideoSource.CAMERA);
// 设置视频文件的输出格式
// 必须在设置声音编码格式、图像编码格式之前设置
mRecorder.setOutputFormat(MediaRecorder
.OutputFormat.THREE_GPP);
// 设置声音编码的格式
mRecorder.setAudioEncoder(MediaRecorder
.AudioEncoder.AMR_NB);
// 设置图像编码的格式
mRecorder.setVideoEncoder(MediaRecorder
.VideoEncoder.H264);
mRecorder.setVideoSize(1280, 720);
// 每秒 4帧
mRecorder.setVideoFrameRate(20);
mRecorder.setOutputFile(videoFile.getAbsolutePath());
// 指定使用SurfaceView来预览视频
mRecorder.setPreviewDisplay(sView
.getHolder().getSurface()); //①
mRecorder.prepare();
// 开始录制
mRecorder.start();
}
catch (Exception e)
{
Log.e("MyRcoder", e.getMessage());
}

}
...全文
116 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
SpringRegister 2015-03-04
  • 打赏
  • 举报
回复
兄台解决了吗?: invalid preview surface

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧