Sto riproducendo un video in UITableViewCell
. Per questo sto usando il seguente codice:Come riprodurre un video (riproduzione automatica) in UITableViewCell in iOS
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *VideoCellIdentifier = @"VideoCell";
NSDictionary *_response_data = [self.response objectAtIndex:indexPath.row];
VideoCustomCell *cell = (VideoCustomCell *) [tableView dequeueReusableCellWithIdentifier:VideoCellIdentifier];
if (cell == nil) {
NSArray *topLevelObjects;
topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"VideoCustomCell" owner:self options:nil];
for (id currentObject in topLevelObjects){
if ([currentObject isKindOfClass:[UITableViewCell class]]){
cell = (VideoCustomCell *) currentObject;
cell.delegate = self;
break;
}
}
}
avPlayer = [[AVPlayer playerWithURL:[NSURL URLWithString:[_response_data valueForKey:@"media_id"]]] retain];
avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
avPlayerLayer.frame = cell.video_player_view.layer.bounds;
avPlayerLayer.videoGravity = AVLayerVideoGravityResize;
[cell.video_player_view.layer addSublayer: avPlayerLayer];
[avPlayer play];
return cell;
}
la riproduzione del video correttamente, ma voglio giocare un solo video alla volta. Riproduci il video della cella che è completamente visibile.
Non voglio fare sull'evento click, voglio riprodurre automaticamente il video quando la cella è visibile. – San007
Quindi se vuoi giocare in quel modo non dovresti scrivere il tuo codice in cellforrowatindexpath e scriverlo in viewWillAppear e prendere il ciclo per array e riprodurlo dall'indice dell'array. Ottieni il tempo pieno del brano e, una volta completato, carica il brano successivo da quell'array. Usa la tabella solo per scopi di visualizzazione con una certa logica che suona la canzone. – user2826529
Non hai problemi, grazie per il tuo impegno. – San007