gpt4 book ai didi

ios - 从库/缓存加载视频到 View

转载 作者:行者123 更新时间:2023-11-29 01:02:02 25 4
gpt4 key购买 nike

对于我的应用程序,我希望用户录制一个视频,该视频将存储在缓存目录中,以便在整个应用程序中重复使用。

NSString *DestFilename = @ "output.mov";

//Set the file save to URL
NSLog(@"Starting recording to file: %@", DestFilename);
NSString *DestPath;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
DestPath = [paths objectAtIndex:0];
DestPath = [DestPath stringByAppendingPathComponent:DestFilename];

NSURL* saveLocationURL = [[NSURL alloc] initFileURLWithPath:DestPath];
[MovieFileOutput startRecordingToOutputFileURL:saveLocationURL recordingDelegate:self];

NSLog 说:

url = file:///var/mobile/Containers/Data/Application/BD41ABB0-77BA-4872-B447-07906A3C6FA7/Library/Caches/output.mov

如何加载或嵌入该视频到 Storyboard中的某个 ViewController 中?

最佳答案

基本上,您的视频 URL 就在那里,因此您可以将视频加载到 View Controller 中并以 2 种可能的方法播放它:使用 MPMoviePlayerController 或 AVPlayer

例如从你的 View Controller

    //The first approach
self.moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:saveLocationURL];
[self.moviePlayerController.view setFrame: CGRectMake(0, 0, 1024, 768)];
[self.view addSubview:self.moviePlayerController.view];

[self.moviePlayerController play];

//The second approach
self.playerItem = [AVPlayerItem playerItemWithURL:saveLocationURL];
self.player = [AVPlayer playerWithPlayerItem:playerItem];

AVPlayerLayer *layer = [AVPlayerLayer playerLayerWithPlayer:self.player];
layer.frame = CGRectMake(0, 0, 1024, 768);

[self.view.layer addSublayer:layer];
[self.player play];

希望对您有所帮助。

关于ios - 从库/缓存加载视频到 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36891179/

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