Хорошо, поэтому я не смог правильно опубликовать свой код в прошлый раз ... Я новичок. Я немного изменил вещи, и я пытаюсь заставить видео воспроизводиться из uiTableView. У меня не происходит сбоя, я просто получаю черный экран в течение примерно 20 секунд, а затем симулятор или iPhone возвращается к uiTableView. Когда я выбираю «вариант 1», я получаю предупреждение, как и ожидалось. Я использую Xcode 4.2 для iOS 4.0.
Я искал и стучал головой несколько дней, и любая помощь приветствуется.
Вот мой .х
#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>
@interface faq2 : UITableViewController
{
NSArray *faqList;
}
@property (nonatomic, strong) NSArray *faqList;
-(IBAction)playMovie;
@end
Вот мой .m
-(IBAction)playMovie
{
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"WhatFinalTake" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.faqList = [[NSArray alloc] initWithObjects:
@"Play Movie",
@"Option 1", nil];
self.title = @"Frequently Asked Questions";
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
self.faqList = nil;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [faqList count];
}
- (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];
}
// Configure the cell.
cell.textLabel.text = [self.faqList objectAtIndex: [indexPath row]];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0)
{
[self playMovie];
}
else if (indexPath.row == 1)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Option 1" message:@"Option 1" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil, nil];
[alert show];
}
}
Я почти уверен, что добавил фреймворк, но вот скриншот.
![enter image description here](https://i.stack.imgur.com/2XS1h.png)