Еще одно решение для дублирования видеоплеерыНепризнанный селектор при использовании MPMoviePlayerController
-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
[_moviePlayerR stop];
[_moviePlayerR.view removeFromSuperview];
}
EDIT ВОПРОС
Я редактировал код с пользовательской ячейке, он хорошо работает и не проблема аварии, но новая проблема когда видео работает, если Im прокрутка видео дублируется в другой ячейке, как я могу воспроизвести видео только в текущей ячейке.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *sessionCellID = @"imageID";
static NSString *noneID = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:noneID];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:noneID];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if(indexPath.row == 0) {
TimeLineCell *cell = nil;
cell = (TimeLineCell *)[tableView dequeueReusableCellWithIdentifier:sessionCellID];
if(!cell) {
cell = [[TimeLineCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:sessionCellID];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.mainImage.tag = indexPath.section;
dispatch_async(dispatch_get_main_queue(), ^{
[cell.mainImage setImageWithURL:[NSURL URLWithString:[pictures objectAtIndex:indexPath.section]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"] ];
});
UITapGestureRecognizer* tapu = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)];
tapu.numberOfTouchesRequired = 1;
[cell.mainImage setUserInteractionEnabled:YES];
[cell.mainImage addGestureRecognizer:tapu];
return cell;
}
return cell;
}
-(void)tapImage:(UITapGestureRecognizer *)gestureRecognizer {
CGPoint tapLocation = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *tapIndexPath = [self.tableView indexPathForRowAtPoint:tapLocation];
TimeLineCell* tappedCell = (TimeLineCell*)[[self.tableView cellForRowAtIndexPath:tapIndexPath] viewWithTag:tapIndexPath.section];
NSURL *movieURL = [NSURL URLWithString:[videourl objectAtIndex:tapIndexPath.section]];
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: movieURL];
[player prepareToPlay];
[player.view setFrame: tappedCell.mainImage.bounds];
_moviePlayerR=player;
[tappedCell.mainImage.viewForBaselineLayout addSubview: _moviePlayerR.view];
[_moviePlayerR play];
}
Я использовал разделы и каждый раздел имел строки, чтобы изображение для первой строки.
Я написал этот код, который имеет tableView, каждая ячейка имеет загрузку изображений с помощью SDWebImage, и каждое изображение имеет UITapGesture, если пользователь прикасается к любому изображению, он должен воспроизводить видео по текущей ячейке.
Он хорошо работает, но пользователь прокручивает во время воспроизведения видео он делает проблему аварии, как это сообщение:
- [MPVideoBackgroundView setImage]: непризнанные селектор послал к примеру 0x175e65c0
Это код:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Main";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIImageView *showImage;
showImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, 310)];
showImage.tag = 99;
[cell addSubview:showImage];
}
else {
showImage = (UIImageView*)[cell viewWithTag:99];
}
UITapGestureRecognizer* tapu = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)];
tapu.numberOfTouchesRequired = 1;
showImage.tag = indexPath.section;
[showImage setUserInteractionEnabled:YES];
[showImage addGestureRecognizer:tapu];
dispatch_async(dispatch_get_main_queue(), ^{
[showImage setImageWithURL:[NSURL URLWithString:[pictures objectAtIndex:indexPath.section]]
placeholderImage:[UIImage imageNamed:@"placeholder.png"] ];
});
return cell
}
-(void)tapImage:(id)sender {
UITapGestureRecognizer *tapRec = (UITapGestureRecognizer *)sender;
UIImageView *label = (UIImageView *)tapRec.view;
NSURL *movieURL = [NSURL URLWithString:[videourl objectAtIndex:label.tag]];
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: movieURL];
[player prepareToPlay];
[player.view setFrame: label.bounds];
self.moviePlayerR=player;
[label.viewForBaselineLayout addSubview: self.moviePlayerR.view];
[self.moviePlayerR play];
}
Для вашей информации, структура MediaPlayer включена в файл .h и я установил Prope rty для (self.moviePlayerR) в .h и синтезируйте его в .m
Пожалуйста, уменьшите пустые строки в коде, потому что это заставляет людей читать ваш вопрос, чтобы выполнить дополнительную работу. Также обратите внимание, что Stackoverflow имеет отличную функцию тегирования, поэтому теги совершенно не нужны в заголовке. – dandan78
Спасибо за редактирование, и извините за это –