Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-26-2011, 04:45 AM   #1 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 18
MSP4444 is on a distinguished road
Unhappy Play a video from a table view

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...

Code:
- (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
MSP4444 is offline   Reply With Quote
Old 04-26-2011, 07:01 AM   #2 (permalink)
I will be a billionaire.
 
IphoneSdk's Avatar
 
Join Date: Sep 2009
Location: Scarborough, United Kingdom
Age: 17
Posts: 1,344
IphoneSdk is on a distinguished road
Default

I just made a quick sample App for you! Here is all the code from the .m

Code:
- (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!
__________________
iOS Apps | Website | Twitter | Facebook
IphoneSdk is offline   Reply With Quote
Old 04-26-2011, 10:30 AM   #3 (permalink)
Registered Member
 
Join Date: Apr 2011
Posts: 18
MSP4444 is on a distinguished road
Thumbs up Nice work!

Fantastic! I'll be able to adapt this.

Thanks a lot for that, great work!
MSP4444 is offline   Reply With Quote
Old 08-18-2011, 02:42 AM   #4 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 1
freshmem is on a distinguished road
Default

hi guys..
i`ve been implementing this code..and i`m a bit confused in the .h

this is my code
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
freshmem is offline   Reply With Quote
Reply

Bookmarks

Tags
load, table view, video

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 345
11 members and 334 guests
dansparrow, iOS.Lover, lorrettaui53, Nobbsy, oztemel, pbart, PlutoPrime, samdanielblr, sledzeppelin, thephotographer, Trickphotostudios
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,663
Threads: 94,120
Posts: 402,897
Top Poster: BrianSlick (7,990)
Welcome to our newest member, LezB44
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:51 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0