Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Play a video from a table view

MSP4444MSP4444 Posts: 21Registered Users
edited August 2011 in iPhone SDK Development
Right... This one's had me scratching my head for some time. Does anyone know if it's possible to load a video from a table view. Currently, I'm using this set up to load a new view from each cell...


- (UITableViewCell *)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

NoSamples *noSamplesView = [[NoSamples alloc] initWithNibName:@\"NoSamples\" bundle:nil];
NoTamborim *noTamborimView = [[NoTamborim alloc] initWithNibName:@\"NoTamborim\" bundle:nil];
Maintenance *MaintenanceView = [[Maintenance alloc] initWithNibName:@\"Maintenance\" bundle:nil];

switch (indexPath.row)
{
case 0:
[self.navigationController pushViewController:noSamplesView animated:YES];
break;
case 1:
[self.navigationController pushViewController:noTamborimView animated:YES];
break;
default:
[self.navigationController pushViewController:MaintenanceView animated:YES];
break;
}

}


I'd just like to know whether I can use the 'switch (indexpath.row)' function to load a video rather than a new view.

I've previously tried loading the new view then using the video code under 'viewDidLoad' but didn't have much luck. I could hear the video playing but only the navigation controller was visible with a white background.

Any help would be appreciated.

Cheers
Post edited by MSP4444 on

Replies

  • IphoneSdkIphoneSdk Posts: 1,388Registered Users
    edited April 2011
    I just made a quick sample App for you! Here is all the code from the .m


    - (void)viewDidLoad {
    [super viewDidLoad];

    tableList = [[NSMutableArray alloc] initWithObjects:
    @\"Video 1\",
    @\"Video 2\",

    nil];

    self.title = @\"App Title\";

    }

    // Customize the number of sections in the table view.
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
    }


    // Customize the number of rows in the table view.
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [tableList count];
    }


    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @\"Cell\";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }


    [cell.textLabel setText:[[tableList objectAtIndex:indexPath.row] retain]];
    [cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];

    cell.textLabel.textColor = [UIColor darkGrayColor];


    return cell;
    }

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *str= [tableList objectAtIndex:indexPath.row];
    if ([str isEqual:@\"Video 1\"])
    {

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@\"video\" ofType:@\"mp4\"];
    NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    [theMovie play];
    MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
    [self presentMoviePlayerViewControllerAnimated:moviePlayer];

    }

    else if ([str isEqual:@\"Video 2\"])
    {

    NSBundle *bundle = [NSBundle mainBundle];
    NSString *moviePath = [bundle pathForResource:@\"video\" ofType:@\"mp4\"];
    NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
    MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    theMovie.scalingMode = MPMovieScalingModeAspectFill;
    [theMovie play];
    MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
    [self presentMoviePlayerViewControllerAnimated:moviePlayer];

    }
    }


    Hope that helps! And by the way, remember to import your MediaPlayer framework! :)
  • MSP4444MSP4444 Posts: 21Registered Users
    edited April 2011
    Fantastic! I'll be able to adapt this.

    Thanks a lot for that, great work!
  • freshmemfreshmem Posts: 1New Users
    edited August 2011
    hi guys..
    i`ve been implementing this code..and i`m a bit confused in the .h

    this is my code

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

    @interface videoLessonsViewController : UIViewController {
    UITableView *_tableViewVideo;
    NSMutableArray *tableList;
    UITableViewCell *_cell;
    MPMoviePlayerViewController *moviePlayer;

    }


    and still has many errors.one of error say that my table list is undeclared..
    any suggestion guys?
    thank you
Sign In or Register to comment.