0

我正在播放MPMoviePlayerView中的视频,该视频位于我的分屏视图的详细视图中。iPad UISplitView UIDetailView播放MPMoviePlayerController无视频。

- (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]; 
} 

我想解决的问题是:如果我在执行下面的代码的详细视图创建自己的播放按钮

一切正常。当有人点击一个主视图tableview单元格时,我想要在不使用播放按钮的情况下加载电影。当我没有播放按钮加载电影时,音频播放但没有视频。视图是空白的。

当用户按下在Interface Builder中链接的按钮时,发生这种情况时会发生什么情况,而不是以编程方式调用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]; 
} 
} 

,这里是我做什么配置的DetailView:

#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); 

} 

回答

0

明白了!

原来,我需要从didSelectRowAtIndexPath表视图方法消息detailViewController然后加载视图到视图。

相关问题