iPad UISplitView UIDetailView播放MPMoviePlayerController没有视频。有点

时间:2012-04-03 13:12:20

标签: iphone ios ipad mpmovieplayercontroller uisplitviewcontroller

我正在MPMoviePlayerView中播放电影,这是我对splitview的详细视图。

如果我在执行以下代码的详细信息视图中创建自己的“播放”按钮,则一切正常:

- (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 tableview单元格时,我希望在不使用播放按钮的情况下加载电影。当我在没有播放按钮的情况下加载电影时,音频播放但没有视频。视图是空白的。

当用户按下Interface Builder中链接到该操作的按钮而不是以编程方式调用loadMoviPlayer时,是否会发生我遗漏的事情?

这是我的masterviewcontroller中的didSelectTableViewCell:

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

}

1 个答案:

答案 0 :(得分:0)

知道了!

结果我需要从didSelectRowAtIndexPath表视图方法发出detailViewController的消息,然后将影片加载到视图中。