gpt4 book ai didi

ios - 如何访问相册中的视频并播放?

转载 作者:行者123 更新时间:2023-11-29 11:14:40 26 4
gpt4 key购买 nike

以下代码用于将视频保存到相册。

else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{

NSString *sourcePath = [[info objectForKey:@"UIImagePickerControllerMediaURL"]relativePath];
UISaveVideoAtPathToSavedPhotosAlbum(sourcePath,nil,nil,nil);
}

如果是视频我想播放它如果是图片我想显示它。

帮帮我。

最佳答案

用代码检查是图片还是视频:

    NSString *mediaType1 = [info objectForKey:UIImagePickerControllerMediaType];
NSLog(@"mediaType : %@",mediaType1);

if ([mediaType1 isEqualToString:@"public.image"])
{
//Show Image
}
else
{
//show Video
}

要播放视频,请检查 URL .

编辑:

        NSString *moviePath = [bundle pathForResource:@"IMG_0017" ofType:@"MOV"];
NSLog(@"moviePath : %@",moviePath);
// NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];

NSURL *movieURL = [NSURL URLWithString:strValURL];
NSLog(@"movieURL : %@",movieURL);
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2)
{
NSLog(@"> 3.2");
MPMoviePlayerViewController *mp = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
if (mp)
{
[self presentMoviePlayerViewControllerAnimated:mp];
mp.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[mp.moviePlayer play];
[mp release];
}
}
else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2)
{
NSLog(@"< 3.2");
theMovie = [[MPMoviePlayerController alloc] initWithContentURL: movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(myMovieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object: theMovie];
[theMovie play];
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
MPMoviePlayerViewController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer release];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void) movieFinishedCallback:(NSNotification*) aNotification
{
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player autorelease];
}

关于ios - 如何访问相册中的视频并播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10006312/

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