2013-05-10 46 views
0

我正在開發一個視頻管理應用程序。我在滾動視圖上添加視頻。我們如何在滾動條上添加視頻?

除黑屏外沒有任何可見的東西。此代碼正常工作,只在滾動中添加黑色視圖,顯示內容。

如果任何人有任何想法,請提供給我。

(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++; 
     } 
    } 
} 

我已開發此代碼。

回答

0

您需要使用AVPlayer而不是MPMoviePlayerControllerAVPlayer一樣,您可以將視頻渲染到特定的源視圖 - 在您的情況下爲scrollview。

好運

0

你沒叫玩兒法

// Plays items from the current queue, resuming paused playback if possible. 
- (void)play; 

嘗試下一個代碼

_moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:filePath]]; 

[[_moviePlayer view] setFrame:[[self view] bounds]]; 
[[self view] addSubview: [_moviePlayer view]]; 

_moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 

[_moviePlayer play]; 

如果你有一個許多影片scrollview你將遇到內存問題管理,爲了優化顯示視頻列表的過程,您可以使用UITableView並將視頻放在每個單元格上,因爲UITableView已經擁有自己的單元格內存管理器。