我正在开发一个视频管理应用程序。我在滚动视图上添加视频。我们如何在滚动条上添加视频?
除黑屏外没有任何可见的东西。此代码正常工作,只在滚动中添加黑色视图,显示内容。
如果任何人有任何想法,请提供给我。
(void)LoadVideosToScrollView
{
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory=[paths objectAtIndex:0];
NSString *videoDirectory=[documentDirectory stringByAppendingPathComponent:@"/videos"];
NSFileManager *fileManger=[NSFileManager defaultManager];
NSDirectoryEnumerator *docEnum=[fileManger enumeratorAtPath:videoDirectory];
MPMoviePlayerController *localMoviePlayer;
CGFloat xAxis=10;
NSInteger n=0;
NSString *fileName;
[self.scrollView setContentSize:CGSizeMake(560, 200)];
while ((fileName=[docEnum nextObject]))
{
NSString *filePath=[videoDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@",fileName]];
//if file exist then file will be added on ScrollView
if ([fileManger fileExistsAtPath:filePath])
{
NSURL *urlForFile=[NSURL fileURLWithPath:filePath];
NSLog(@"%@",[urlForFile description]);
localMoviePlayer=[[MPMoviePlayerController alloc]initWithContentURL:urlForFile];
localMoviePlayer.scalingMode=MPMovieScalingModeAspectFit;
localMoviePlayer.shouldAutoplay=NO;
localMoviePlayer.controlStyle=MPMovieControlStyleNone;
[localMoviePlayer prepareToPlay];
tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
[localMoviePlayer.view addGestureRecognizer:tap];
[localMoviePlayer.view setTag:n];
[localMoviePlayer.view setFrame:CGRectMake(xAxis,5,150,120)];
[self.scrollView addSubview:localMoviePlayer.view];
[moviePlayerContainer addObject:urlForFile];
xAxis+=155;
n++;
}
}
}
我已开发此代码。