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然後加載視圖到視圖。

相關問題