gpt4 book ai didi

iphone - 在 IOS 5 中从 UIImagePickerController 保存视频

转载 作者:行者123 更新时间:2023-11-28 17:39:11 28 4
gpt4 key购买 nike

到目前为止,我一直使用这段代码来保存从 UIImagePickerController 获取的视频:

        NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];

NSData *videoData = [NSData dataWithContentsOfURL:url];
path = [kFilesSaveDirectory stringByAppendingFormat:@"%@/Vid%d.mov",album.albumName,album.lastfile];
path2 = [kFilesSaveDirectory stringByAppendingFormat:@"%@/VidImg%d.png",album.albumName,album.lastfile];

[videoData writeToFile:path atomically:NO];

[[videoPlayer moviePlayer] setContentURL:[NSURL URLWithString:path]];
UIImage *image = [[videoPlayer moviePlayer] thumbnailImageAtTime:1.0 timeOption: MPMovieTimeOptionNearestKeyFrame];
[[videoPlayer moviePlayer] setContentURL:nil];
[UIImagePNGRepresentation(image) writeToFile:path2 atomically:YES];

直到现在在 ios 4 中它工作没有任何问题,但是当我现在尝试在 ios 5 中使用它时,它有两个问题:

  1. 它给我的 img 为 nil。

2.当我想用这段代码显示视频时,它不显示视频:

[[videoPlayer moviePlayer] setContentURL:[NSURL URLWithString:choosen.bigpath]];

[self presentModalViewController:videoPlayer animated:YES];

[[videoPlayer moviePlayer] play];

最佳答案

这对我有用 -

NSURL *mediaUrl = [info objectForKey:UIImagePickerControllerMediaURL];

MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:mediaUrl];
moviePlayer.shouldAutoplay = NO;
thumbnail = [[moviePlayer thumbnailImageAtTime:0.0 timeOption:MPMovieTimeOptionNearestKeyFrame] retain];
[moviePlayer release];
[layer release];

我将此代码添加到此委托(delegate)

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 

希望它也对你有用:)

关于iphone - 在 IOS 5 中从 UIImagePickerController 保存视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8832445/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com