Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong><em>VideoTableCell.h</em></strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import &lt;AVFoundation/AVFoundation.h&gt; @interface VideoTableCell : UITableViewCell @property (strong, nonatomic) IBOutlet UIView *viewForVideo; @property (strong, nonatomic) IBOutlet UIImageView *imgThumb; @property (strong, nonatomic) IBOutlet UIButton *btnPlay; @property (strong, nonatomic) AVPlayerItem* videoItem; @property (strong, nonatomic) AVPlayer* videoPlayer; @property (strong, nonatomic) AVPlayerLayer* avLayer; @end </code></pre> <p><strong><em>VideoTableCell.m</em></strong></p> <pre><code>#import "VideoTableCell.h" @implementation VideoTableCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; return self; } - (void)layoutSubviews { [super layoutSubviews]; [self.avLayer setFrame:CGRectMake(self.viewForVideo.frame.origin.x, self.viewForVideo.frame.origin.y, self.viewForVideo.frame.size.width, self.viewForVideo.frame.size.height)]; } @end </code></pre> <p><strong><em>VideoVC.h</em></strong></p> <pre><code>#import &lt;UIKit/UIKit.h&gt; #import &lt;AVFoundation/AVFoundation.h&gt; @interface VideoVC : UIViewController &lt;UITableViewDataSource, UITableViewDelegate&gt; @property (strong, nonatomic) IBOutlet UITableView *tblData; @end </code></pre> <p><strong><em>VideoVC.m</em></strong></p> <pre><code>#import "VideoVC.h" #import "VideoTableCell.h" @interface VideoVC () { NSArray *arrVideo ; bool isScrolling; int index; BOOL fullvisible ; } @end @implementation VideoVC - (void)viewDidLoad { [super viewDidLoad]; arrVideo = [[NSArray alloc]initWithObjects:@"http://video/1.mp4",@"http://video/2.mp4", @"http://video/3.mp4", @"http://video/4.mp4", @"http://video/5.mp4", nil]; fullvisible = YES; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return arrVideo.count; } - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { VideoTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VideoTableCell"]; if (cell == nil) { cell = [[[NSBundle mainBundle] loadNibNamed:@"VideoTableCell" owner:self options:nil]objectAtIndex:0]; } int temp = [self getVisibleIndex]; if (temp == indexPath.row &amp;&amp; fullvisible) { cell.imgThumb.hidden = YES ; //NSLog(@"fullvisible == 1"); NSURL *url = [NSURL URLWithString:[arrVideo objectAtIndex:indexPath.row]]; cell.videoItem = [AVPlayerItem playerItemWithURL:url]; cell.videoPlayer = [AVPlayer playerWithPlayerItem:cell.videoItem]; cell.avLayer = [AVPlayerLayer playerLayerWithPlayer:cell.videoPlayer]; [cell.avLayer setBackgroundColor:[UIColor whiteColor].CGColor]; // [cell.avLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill]; [cell.contentView.layer addSublayer:cell.avLayer]; [cell.videoPlayer play]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; } else { cell.imgThumb.hidden = NO ; cell.videoPlayer = nil; [cell.avLayer removeFromSuperlayer]; cell.videoItem = nil; [cell.videoPlayer pause]; } return cell ; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 393 ; } - (int)getVisibleIndex { for (NSIndexPath *indexPath in _tblData.indexPathsForVisibleRows) { CGRect cellRect = [_tblData rectForRowAtIndexPath:indexPath]; BOOL isVisible = CGRectContainsRect(_tblData.bounds, cellRect); if (isVisible) { index = (int)indexPath.row ; } } return index ; } - (void)scrollViewDidScroll:(UIScrollView *)aScrollView { NSArray* cells = _tblData.visibleCells; for (VideoTableCell* cell in cells) { NSIndexPath *path = [_tblData indexPathForCell:cell]; index = (int) path.row; fullvisible = YES; [_tblData reloadData]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload