gpt4 book ai didi

iphone - 如何从目录中读取文件

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

我有一个别人写的项目。该项目将视频文件保存在此路径中,file://localhost/var/mobile/Applications/CAC8F2CB-1C7D-4805-BF1A-42B63B258E95/Documents/output.mp4

我想用 MPMoviePlayerController 播放文件,如何访问文件?

最佳答案

首先加载路径和文件URL:

NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,    NSUserDomainMask, YES) objectAtIndex:0];

NSString *localFilePath = [photoDirectoryPath stringByAppendingPathComponent:@"output.mp4"];

然后使用 URL 加载 MPMoviePlayerController

- (void)initMoviePlayer 
{
didExit = NO;

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePreloadDidFinish:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:mMoviePlayer];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];

NSLog(@"initMoviePlayer: %@ ",[self getMovieURL]);

mMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[self getMovieURL]];

mMoviePlayer.shouldAutoplay = YES;

mMoviePlayer.view.hidden = YES;

[mMoviePlayer setControlStyle:MPMovieControlStyleNone];

mMoviePlayer.view.frame = [self.view bounds];

mMoviePlayer.scalingMode = MPMovieScalingModeNone;

[[self view] addSubview:[mMoviePlayer view]];

[mMoviePlayer play];

}

- (void) moviePreloadDidFinish:(NSNotification*)notification {

// start playing the movie

mMoviePlayer.view.hidden = NO;

animateTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
target:self
selector:@selector(playMovie:)
userInfo:nil
repeats:NO];
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification
{

}

关于iphone - 如何从目录中读取文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14953243/

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