【问题标题】:how can we add videos on scrollbar?我们如何在滚动条上添加视频?
【发布时间】:2013-05-10 07:29:10
【问题描述】:

我正在开发一个视频管理应用程序。我在滚动视图上添加视频。

除了黑屏,什么都看不见。此代码工作正常,只在滚动时添加黑色视图,显示内容。

如果有人有任何想法,请提供给我。

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

我已经开发了这段代码。

【问题讨论】:

    标签: iphone ios xcode ios6


    【解决方案1】:

    您需要使用AVPlayer 而不是MPMoviePlayerControllerAVPlayer 一样,您可以将视频渲染到特定的源视图 - 在您的情况下是滚动视图。

    祝你好运

    【讨论】:

      【解决方案2】:

      你没有调用 play 方法

      // 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];
      

      如果你在一个滚动视图上有很多视频,你会遇到内存管理问题,为了优化显示视频列表的过程,你可以使用 UITableView 并将视频放在每个单元格上,因为 UITableView 已经有自己的单元格内存管理器.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-12-14
        • 2011-11-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-21
        • 2013-08-17
        相关资源
        最近更新 更多