Playing Video URL from Table View Selection

Hi All,

I have searched everywhere and have not found an answer, so I have come here. I am in Xcode 5 and I am trying to use a Table View to play a video (from an array) when the cell is clicked. I created a Master-Detail Application and done the following.

  1. I have added the Media Player framework
  2. Imported this into the “Master View Controller”
  3. Added the following code to the -(void) prepareForSegue method

MasterViewController.h


#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface MasterViewController : UITableViewController <UITableViewDelegate>

@property (strong, nonatomic) NSDictionary *presidents;
@property (strong, nonatomic) NSArray *number;
@property (strong, nonatomic) NSArray *name;
@property (strong, nonatomic) NSArray *years;
@property (strong, nonatomic) NSArray *party;
@property (strong, nonatomic) NSArray *image;
@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;

@end


MasterViewController.m


- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
if ([[segue identifier] isEqualToString:@"showDetail"]) {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

    NSURL *movieURL = [party objectAtIndex:indexPath.row];
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL];
    [[player view] setFrame:[self.view bounds]];
    [self.view addSubview:[player view]];
    [player play];

    MPMoviePlayerViewController *playVideo = [[MPMoviePlayerViewController alloc]initWithContentURL];

    //NSDate *object = _objects[indexPath.row];
    [[segue destinationViewController] presentMoviePlayerViewControllerAnimated:playVideo];
}
 }

This did not work, so I then also tried to use the -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath method.


-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSURL *movieURL = [party objectAtIndex:indexPath.row];
    _moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL];
    _moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
    _moviePlayer.view.frame = CGRectMake(0, 60, 320, 350);
    [self.view addSubview:_moviePlayer.view];
    [self.moviePlayer play];
}


The error I am getting on both is the: Thread 1: signal SIGABRT

Hopefully, I have given enough information, but I will be happy to post more code. Thank you for your help.

Hi,

as far as I can see the master view controller contains the table view so
you have to put the movie player into the detail view controller and switch the view

Hi Stefan,

Thank you for your reply. So, I would use the

  • (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
    if ([[segue identifier] isEqualToString:@“showDetail”]) {
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

but I should instantiate the MPMoviePlayerController in a UIView in the DetailViewController?

Thank you.