Android视频如何捕捉示例应用程序?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (16)

有没有一个独立的示例代码在Android中进行视频捕捉?

提问于
用户回答回答于

启动意图,捕捉视频,然后返回到你的活动,并通过onActivityResult访问视频:

// Setup a result flag for your video capture
int ACTION_TAKE_VIDEO = 100;

// Launch an intent to capture video from MediaStore
Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(takeVideoIntent, ACTION_TAKE_VIDEO);

// Obtain the file path to the video in onActivityResult
public void onActivityResult(int requestCode, int resultCode, Intent data) {

if (resultCode == RESULT_OK) {

    if (requestCode == ACTION_TAKE_VIDEO) {

        Uri videoUri = data.getData();
        String filePath = getPath(videoUri);
        Log.d("LOGCAT", "Video path is: " + filePath);
    }
}

扫码关注云+社区