如何在我的应用中播放视频

时间:2016-08-11 07:08:17

标签: ios objective-c video mpmovieplayercontroller uicollectionviewcell

我已经记录了输出,它是url formate文件://// var / mobile / Containers / Data / Application / 5421D684-D466-44F1-AEF5-7390598B5647 / Documents / 2016-07-29-17-00 -12-0.MOV。 2016-07-29-17-00-12-0.MOV这是每次录制更改时的时间戳,我希望使用mpmovie播放器或avmediaplayer在我的应用中播放该视频。

如果你理解我会解释这个过程请问我会尽快解释清楚。

  1. 我通过recoredvideooutput url将通知传回给其他视图控制器 2.在视图控制器中,我检索我的网址并将其转换为数组。 [urlarray addObject:finalsharevideourl];

    3.我将urlarray添加到otherarray,其中包含这样的图像

    [app.array1 insertObject:[urlarray firstObject] atIndex:0]; 4.现在我在集合视图单元格中声明了mpmovieplayer

    @property(强大,非原子)MPMoviePlayerController * movieplayer;

  2. 5.现在我想播放视频并在集合视图单元格中添加图片,这是我的代码

    UIImage *image;
    NSInteger row = [indexPath row];
    
    
    NSLog(@"indexpath = %ld", (long)row);
    
    
    if ([app.array1[row] isKindOfClass:[UIImage class]])
    {
        image= app.array1[row];
    }
    else if ([app.array1[row] isKindOfClass:[NSURL class]])
    {
    
    
    
        if (!(finalsharevideourl == 0))
        {
                cell.movieplayer = [[MPMoviePlayerController alloc]initWithContentURL:finalsharevideourl];
    
                //[cell.movieplayer.view setFrame:CGRectMake(10, 50, 100, 50)];
                cell.movieplayer.view.frame = cell.img.frame;
                [self.view addSubview:cell.movieplayer.view];
    
    
                [cell.movieplayer play];
             [cell insertSubview:cell.movieplayer.view atIndex:0];
    
        }
    
    }
      else
          {
            image = [UIImage imageNamed:app.array1[row]];
    
           }
            cell.img.image = image;
    
            cell.text.text=[app.tarray1 objectAtIndex:indexPath.row];
             [cell insertSubview:cell.movieplayer.view atIndex:0];
    
            return cell;
    

    }

    *我希望视频在图像视图上播放,我想要一个图像视图用于图像和视频,如果数据源是视频,它应该在图像视图上播放,否则图像在img视图上。
    视频正在第0个索引路径的单元格中播放, 问题是 1.当我将视频添加到单元格时,视频正在第0个索引处播放,它正在播放我所有的单元格而不是图像视图。 2.当我将图像添加到单元格时,图像将在第0个索引处,视频索引路径为2,在这种情况下,我希望视频播放。

0 个答案:

没有答案
相关问题