Note that there are some explanatory texts on larger screens.

plurals
  1. POUnrecognized selector while using MPMoviePlayerController
    text
    copied!<p><strong>Another Solution for duplicating movie players</strong></p> <pre><code>-(void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView { [_moviePlayerR stop]; [_moviePlayerR.view removeFromSuperview]; } </code></pre> <p><strong>EDIT QUESTION</strong></p> <p>I edited the code with custom cell, it works well and no crash issue but the new problem is when the video is working, if Im scrolling the video is duplicated in another cell how could I play the video in the current cell only.</p> <pre><code>- (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]; } </code></pre> <p>I used sections and each section has rows so the image for the first row.</p> <p>I written this code which it has tableView, each cell has image loading using SDWebImage and every image has UITapGesture, if the user touch any image it must play video over the current cell.</p> <p>It works well, but the user is scrolling while the video is playing it make crash issue as this message:</p> <blockquote> <p>-[MPVideoBackgroundView setImage:]: unrecognized selector sent to instance 0x175e65c0</p> </blockquote> <p>This is the code:</p> <pre><code>- (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]; } </code></pre> <p>For your information, MediaPlayer framework is included in the .h file and I set a property for (self.moviePlayerR) in .h and synthesize it in .m</p>
 

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