Android MediaStore 插入视频
因此我们的应用程序可以选择拍摄照片或视频。如果用户拍照,我们可以使用 MediaStore.Images.Media.insertImage 函数将新图像(通过文件路径)添加到手机的图库中并生成 content:// 样式的 URI。鉴于我们只有文件路径,捕获的视频是否有类似的过程?
So our app has the option to take either a picture or a video. If the user takes a picture, we can use the MediaStore.Images.Media.insertImage function to add the new image (via a filepath) to the phone's gallery and generate a content:// style URI. Is there a similar process for a captured video, given that we only have it's filepath?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是一个简单的“基于单个文件的解决方案”:
每当您添加文件时,让 MediaStore Content Provider 了解它,
主要优点:使用 MediaStore 支持的任何 mime 类型
每当您删除< /strong> 一个文件,让 MediaStore Content Provider 使用以下方式了解它
Here is an easy 'single file based solution':
Whenever you add a file, let MediaStore Content Provider knows about it using
Main advantage: work with any mime type supported by MediaStore
Whenever you delete a file, let MediaStore Content Provider knows about it using
我也感兴趣,请问能找到解决办法吗?
编辑:解决方案是RTFM。基于“内容提供商”一章,这里是我的有效代码:
I'm also interested, could you find a solution?
Edit: solution is RTFM. Based on the "Content Providers" chapter here is my code that worked:
如果您的应用正在生成新视频,并且您只想为 MediaStore 提供一些元数据,则可以在此功能的基础上进行构建:
编辑:从 Android 4.4 (KitKat) 开始,此方法不再有效。
If your app is generating a new video and you simply want to give the MediaStore some metadata for it, you can build on this function:
EDIT: As of Android 4.4 (KitKat), this method no longer works.
我无法让
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE
广播在 API 21 (Lollipop) 下为我工作,但MediaScannerConnection
确实可以工作,例如:I was unable to get the
Intent.ACTION_MEDIA_SCANNER_SCAN_FILE
broadcast to work for me under API 21 (Lollipop), but theMediaScannerConnection
does work, e.g.:试试这个代码。这似乎对我有用。
文件路径示例 -
Try this code. It seems working for me.
Example of filePath -