Android:使用默认录像机录制并返回sd卡路径

发布于 2024-11-28 18:52:26 字数 1489 浏览 4 评论 0原文

我正在尝试开发一个应用程序,它使用默认应用程序记录视频并写入 SD 卡,然后将 SD 卡路径返回到之前的活动。为什么它对我不起作用?当我点击相机中的后退按钮时,我总是被取消吐司。

public class AndroidVideoActivity extends Activity {
    final static int REQUEST_VIDEO_CAPTURED = 1;
    Uri uriVideo = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button btnVideoRecorder = (Button) findViewById(R.id.buttonClick);
        btnVideoRecorder.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent("android.media.action.VIDEO_CAMERA");
                startActivityForResult(intent, REQUEST_VIDEO_CAPTURED);
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        if (resultCode == RESULT_OK) {
            if (requestCode == REQUEST_VIDEO_CAPTURED) {
                uriVideo = data.getData();
                Toast.makeText(AndroidVideoActivity.this, uriVideo.getPath(),
                        Toast.LENGTH_LONG).show();
            }
        } else if (resultCode == RESULT_CANCELED) {
            uriVideo = null;
            Toast.makeText(AndroidVideoActivity.this, "Cancelled!",
                    Toast.LENGTH_LONG).show();
        }

    }
}

I'm trying to develop an application which records the video using default application and writes to sd card and then return the sd card path to previous activity. Why it is not working for me?? i'm getting cancelled toast all the time when I click back button in the camera.

public class AndroidVideoActivity extends Activity {
    final static int REQUEST_VIDEO_CAPTURED = 1;
    Uri uriVideo = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button btnVideoRecorder = (Button) findViewById(R.id.buttonClick);
        btnVideoRecorder.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent("android.media.action.VIDEO_CAMERA");
                startActivityForResult(intent, REQUEST_VIDEO_CAPTURED);
            }
        });

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        if (resultCode == RESULT_OK) {
            if (requestCode == REQUEST_VIDEO_CAPTURED) {
                uriVideo = data.getData();
                Toast.makeText(AndroidVideoActivity.this, uriVideo.getPath(),
                        Toast.LENGTH_LONG).show();
            }
        } else if (resultCode == RESULT_CANCELED) {
            uriVideo = null;
            Toast.makeText(AndroidVideoActivity.this, "Cancelled!",
                    Toast.LENGTH_LONG).show();
        }

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

巴黎盛开的樱花 2024-12-05 18:52:26

您不必点击后退按钮 - 后退按钮 = 取消。您应该能够录制视频,当您停止录制时,您应该按“完成”或类似的按钮(我只使用相机完成此操作,而不是视频),然后它将自动返回到您的应用程序。

You shouldn't have to hit the back button - the back button = cancel. You should be able to record the video, and when you stop recording, you should press 'Done' or something similar (I've only done this with camera, not video), and then it will return to your app automatically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文