Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何跟踪UIImagePickerController创建/选择的媒体?_Ios_Uiimagepickercontroller - Fatal编程技术网

Ios 如何跟踪UIImagePickerController创建/选择的媒体?

Ios 如何跟踪UIImagePickerController创建/选择的媒体?,ios,uiimagepickercontroller,Ios,Uiimagepickercontroller,我正在构建一个iOS应用程序,它允许用户从UIImagePickerController上传视频,可以通过录制或从摄像机卷中选择视频,也可以播放所选视频。我的问题是,我将如何保存以这种方式选择的视频的引用?我想这样做,如果视频仍然存在于设备上,我可以使用本地文件,而不是流式传输上传的文件 什么时候 返回中的URL: [info objectForKey:UIImagePickerControllerMediaURL]; 格式为:file://localhost/private/var/mob

我正在构建一个iOS应用程序,它允许用户从UIImagePickerController上传视频,可以通过录制或从摄像机卷中选择视频,也可以播放所选视频。我的问题是,我将如何保存以这种方式选择的视频的引用?我想这样做,如果视频仍然存在于设备上,我可以使用本地文件,而不是流式传输上传的文件

什么时候

返回中的URL:

 [info objectForKey:UIImagePickerControllerMediaURL];
格式为:file://localhost/private/var/mobile/Applications/ /tmp//trim.z2vLjx.MOV“

我相信“/tmp/”目录是临时的,因此不适合保存该位置的URL

我可以通过AlassetLibrary获取设备上的所有视频,但因为我没有办法区分它们,这对我没有帮助。我一直在尝试使用:

[result valueForProperty:ALAssetPropertyDate];

要区分视频,我需要一种从UIImagePickerController获取创建日期的方法,这样才有用。

您可以轻松地在设备上保存视频记录。要么保留一个数据库(我觉得太多了),要么只是一个包含视频列表的文件。在该列表中,您可以拥有资产的URL

我终于找到了解决方案:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];

if(CFStringCompare((CFStringRef) mediaType,  kUTTypeMovie, 0) == kCFCompareEqualTo)
{
    //Dismiss the media picker view
    [picker dismissModalViewControllerAnimated:YES];

    //Get the URL of the chosen content, then get the data from that URL
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
    NSData *webData = [NSData dataWithContentsOfURL:videoURL];

    //Gets the path for the URL, to allow it to be saved to the camera roll
    NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath))
    {
        ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];

        //The key UIImagePickerControllerReferenceURL allows you to get an ALAsset, which then allows you to get metadata (such as the date the media was created)
        [lib assetForURL:[info objectForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset) {
            NSLog(@"created: %@", [asset valueForProperty:ALAssetPropertyDate]);
        } failureBlock:^(NSError *error) {
            NSLog(@"error: %@", error);
        }];
    }
}

像往常一样,通过更彻底地阅读文档找到了解决方案。希望这能在某个时候帮助其他人。

或者是内容的MD5汇总,这样你就不会有重复的内容了谢伊,谢谢,我已经想到了,不要认为我的问题措辞很好,我会更新它。
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString* mediaType = [info objectForKey:UIImagePickerControllerMediaType];

if(CFStringCompare((CFStringRef) mediaType,  kUTTypeMovie, 0) == kCFCompareEqualTo)
{
    //Dismiss the media picker view
    [picker dismissModalViewControllerAnimated:YES];

    //Get the URL of the chosen content, then get the data from that URL
    NSURL *videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
    NSData *webData = [NSData dataWithContentsOfURL:videoURL];

    //Gets the path for the URL, to allow it to be saved to the camera roll
    NSString *moviePath = [[info objectForKey:UIImagePickerControllerMediaURL] path];
    if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath))
    {
        ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];

        //The key UIImagePickerControllerReferenceURL allows you to get an ALAsset, which then allows you to get metadata (such as the date the media was created)
        [lib assetForURL:[info objectForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset) {
            NSLog(@"created: %@", [asset valueForProperty:ALAssetPropertyDate]);
        } failureBlock:^(NSError *error) {
            NSLog(@"error: %@", error);
        }];
    }
}