I am trying to stream some video when the user presses a row in the tableView. I am using iOS 4.2 and when I press on a row I get sound but the tableview does not push away and you can't see the video? I am sure that this is a huge newbie mistake but... I am a newbie!!! Thanks in advance!!!
-(void)tableView: (UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
NSString *video;
NSString *url;
NSUInteger row = [indexPath row];
video = [self.videoTitles objectAtIndex:row];
if ([video isEqualToString:@"Shimmy"]) {
url = @"http://www.andalee.com/iPhoneVideos/mov.MOV";
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL URLWithString:url]];
[moviePlayer play];
} else if ([video isEqualToString:@"Camel"]) {
url = @"http://www.andalee.com/iPhoneVideos/mov.MOV";
MPMoviePla开发者_如何学编程yerController *moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:[NSURL URLWithString:url]];
[[self view] addSubview:[moviePlayer view]];
[moviePlayer play];
}
[video release];
[url release];
}
For iOS 3.2+, use MPMoviePlayerViewController
.
MPMoviePlayerViewController *moviePlayerController
= [[[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL URLWithString:url]]
autorelease];
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
You're adding the movie player's view to your controller's view, so it will appear on top of all the other views. If that's where you want it to be, you should first set the player view's frame to the bounds of its new superview. For all you know, the player view's bounds could be empty.
If you want the table to slide away to reveal the player view, it might be better to make the player view a subview of another UIViewController's view and then push the other controller on the navigation stack.
精彩评论