Я играю фильмы в MPMoviePlayerView, который находится в моем подробном представлении моего splitview.
Все работает, если я создаю свою собственную кнопку Play в подробном представлении, которое выполняет следующий код:
- (IBAction)buttonPressed:(UIButton *)button
{
// If pressed, play movie
[self loadMoviePlayer];
}
- (void)loadMoviePlayer
{
NSString *videoTitle = [self.detailItem topicVideo];
// Play movie from the bundle
NSString *path = [[NSBundle mainBundle] pathForResource:videoTitle ofType:@"mp4" inDirectory:nil];
// Create custom movie player
moviePlayer = [[NBMoviePlayerViewController alloc] initWithPath:path];
// Show the movie player as modal
//[self presentModalViewController:moviePlayer animated:YES];
playButton.hidden = YES;
moviePlayerView.backgroundColor = [UIColor darkGrayColor];
[moviePlayerView addSubview:moviePlayer.view];
// Prep and play the movie
[moviePlayer readyPlayer];
}
Проблема, которую я хотел бы решить, заключается в следующем.Когда кто-то нажимает на ячейку таблицы просмотра masterview, я хочу, чтобы фильм загружался без использования кнопки воспроизведения.Когда я загружаю фильм без кнопки воспроизведения, воспроизводится звук, но нет видео.представление пустое.
Есть ли что-то, чего мне не хватает, что происходит, когда пользователь нажимает кнопку, которая связана в Интерфейсном Разработчике с этим действием, а не вызывает программный вызов loadMoviPlayer?
Вот мой didSelectTableViewCellв моем masterviewcontroller:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
Subject *subjectSection = [_subjects objectAtIndex:indexPath.section];
Topic *topic = [subjectSection.topics objectAtIndex:indexPath.row];
//NSLog(@"Selected section %d row %d name = %@", indexPath.section, indexPath.row, topic.topicName);
[FlurryAnalytics logEvent:topic.topicName];
self.detailViewController.detailItem = topic;
self.detailViewController.indexRow = indexPath.row;
//SKProduct *product = [[CS6InAppHelper sharedHelper].products objectAtIndex:indexPath.row];
SKProduct *product = [[CS6InAppHelper sharedHelper].products objectAtIndex:[topic.topicIdentifier intValue]];
self.detailViewController.product = product;
NSLog(@"sending product - %@", product.productIdentifier);
NSLog(@"Number of images - %d", [topic.topicImages count]);
[self.detailViewController unloadMoviePlayer];
}
}
и вот что я делаю для настройки подробного просмотра:
#pragma mark - Managing the detail item
- (void)setDetailItem:(id)newDetailItem
{
if (_detailItem != newDetailItem) {
_detailItem = newDetailItem;
// Update the view.
[self configureView];
}
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}
- (void)configureView
{
// Update the user interface for the detail item.
topicImageView1.hidden = YES;
topicImageView2.hidden = YES;
playButton.hidden = YES;
_descriptionLabel.layer.borderColor = [UIColor lightGrayColor].CGColor;
_descriptionLabel.layer.borderWidth = 5;
_descriptionLabel.layer.cornerRadius = 10;
moviePlayerView.layer.borderColor = [UIColor lightGrayColor].CGColor;
moviePlayerView.layer.borderWidth = 5;
moviePlayerView.layer.cornerRadius = 10;
//_toolbar.translucent = YES;
if (self.detailItem) {
if ([[self.detailItem topicIsFree] intValue]) {
NSLog(@"Free topic video");
playButton.hidden = NO;
purchaseButton.hidden = YES;
purchaseAllButton.hidden = YES;
//[self loadMoviePlayer];
} else {
purchaseButton.hidden = NO;
purchaseAllButton.hidden = NO;
playButton.hidden = YES;
}
self.detailDescriptionLabel.text = [self.detailItem topicName];
self.descriptionLabel.text = [self.detailItem topicText];
//NSLog(@"1 - %@",self.descriptionLabel.text);
//NSLog(@"2 - %@",self.detailDescriptionLabel.text);
_numberOfItems = [[self.detailItem topicImages] count];
[self _reloadThumbnailPickerView];
if ([[self.detailItem topicImages] count] >= 1) {
topicImageView1.hidden = NO;
//topicImageView1.backgroundColor = [UIColor redColor];
topicImageView1.contentMode = UIViewContentModeScaleAspectFit;
NSLog(@"Image 1 - %@", [[self.detailItem topicImages] objectAtIndex:0]);
topicImageView1.image = [UIImage imageNamed:[[self.detailItem topicImages] objectAtIndex:0]];
//[topicImageButton.imageView setContentMode: UIViewContentModeScaleAspectFit];
//[topicImageButton setImage:[UIImage imageNamed:[[self.detailItem topicImages] objectAtIndex:0]] forState:UIControlStateNormal];
}
if ([[self.detailItem topicImages] count] >= 2) {
topicImageView2.hidden = NO;
topicImageView2.contentMode = UIViewContentModeScaleAspectFit;
topicImageView2.image = [UIImage imageNamed:[[self.detailItem topicImages] objectAtIndex:1]];
}
} else {
// Initialize thumbnailpicker with no images on startup
_numberOfItems = 0;
NSString *videoTitle = [NSString stringWithFormat:@"Dave_Cross-CS6app"];
// Play movie from the bundle
NSString *path = [[NSBundle mainBundle] pathForResource:videoTitle ofType:@"mp4" inDirectory:nil];
// Create custom movie player
moviePlayer = [[NBMoviePlayerViewController alloc] initWithPath:path];
// Show the movie player as modal
//[self presentModalViewController:moviePlayer animated:YES];
playButton.hidden = YES;
moviePlayerView.backgroundColor = [UIColor grayColor];
[moviePlayerView addSubview:moviePlayer.view];
// Prep and play the movie
[moviePlayer readyPlayer];
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"iPadBackgroundTexture-grey.png"]];
scrollView.contentSize = CGSizeMake(768, 2000);
}