如何删除已取消的视频

发布于 2024-12-28 23:12:07 字数 657 浏览 1 评论 0原文

我正在使用本机相机意图来捕获视频。在 Nexus S 中,如果我捕获视频,那么无论我取消还是按下“确定”,视频文件都会存储在默认的 Medi URI 路径中。但我需要在用户单击“确定”时删除捕获的视频。我正在使用 以下代码调用相机

Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(videoIntent, CAPTURE_VIDEO);

,以下 ciode 处理取消按钮单击事件

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        try {
            if (requestCode == CAPTURE_VIDEO) {if(resultCode == Activity.RESULT_CANCELED) 
//pointer comes here successfully. It tells that cancel button is clicked. But I am unabelt to know how to delete the currently cancelled video
}
}
}

I am using Native Camera intent to capture video. In Nexus S If i capture a video then whether i cancel or pressed ok always the video file is getting store in default Medi URI path. But I have a requirement to delete the captured video when user clicks ok. I am using
following code to call camera

Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
startActivityForResult(videoIntent, CAPTURE_VIDEO);

and following ciode handles cancel button click event

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        try {
            if (requestCode == CAPTURE_VIDEO) {if(resultCode == Activity.RESULT_CANCELED) 
//pointer comes here successfully. It tells that cancel button is clicked. But I am unabelt to know how to delete the currently cancelled video
}
}
}

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

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

发布评论

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

评论(1

老旧海报 2025-01-04 23:12:07

好吧,这是一些丑陋的方式..

首先从返回的 URI 中获取视频的真实路径,就像

private String videoPath = "";

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CAPTURE_VIDEO) 
    {

      Uri vid = data.getData();
      videoPath = getRealPathFromURI(vid);
    }   
}

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Videos.Media.DATA };
    Cursor cursor = managedQuery(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Videos.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

现在你有了视频文件的真实路径,然后使用文件操作你可以删除它。

File videoFile = new File(videoPath);
videoFile.deleteOnExit();

我怀疑是否有任何方法可以从 android 数据库中删除它。

Ok, Its some ugly way..

First get the real path of the video from returned URI, like

private String videoPath = "";

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == CAPTURE_VIDEO) 
    {

      Uri vid = data.getData();
      videoPath = getRealPathFromURI(vid);
    }   
}

public String getRealPathFromURI(Uri contentUri) {
    String[] proj = { MediaStore.Videos.Media.DATA };
    Cursor cursor = managedQuery(contentUri, proj, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Videos.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

Now you have a real path of video file then using file operation you can delete it.

File videoFile = new File(videoPath);
videoFile.deleteOnExit();

I doubt if there is available any method to delete it form android database..

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