Android: How to initialize MediaRecorder without a valid surface for video preview?

后端 未结 4 2008
余生分开走
余生分开走 2020-12-31 12:53

I am building a camera app, where videos are continuously being captured and saved to the SD card. The videos are short (few minutes), and their length are preset with setMa

相关标签:
4条回答
  • 2020-12-31 13:27

    Are you implementing Surface callbacks?

    Why do you need to initialize MediaRecorder without a valid surface?

    Are you supposed to be recording even when you leave the main activity? or does recording stop before the other acitivty is spawned?

    0 讨论(0)
  • 2020-12-31 13:31

    I think the IP Webcam app can do this, though I don't know how. Maybe it only works on >=2.3. I'm not sure what version I saw it running on. I asked a question to find how how it's working.

    0 讨论(0)
  • 2020-12-31 13:40

    Unfortunately it is still a requirement for you to preview onto a valid surface in order to record video (Android SDK 1.6 thru 2.2). There is an enhancement request logged to remove this restriction http://code.google.com/p/android/issues/detail?id=9570

    0 讨论(0)
  • 2020-12-31 13:42

    You just have to create a surface with MediaCodec by adding the following line:

    Surface  mySurface = MediaCodec.createPersistentInputSurface();
    mMediaRecorder.setPreviewDisplay(mySurface);
    
    ...
    
    mMediaRecorder.prepare();
    
    0 讨论(0)
提交回复
热议问题