Все еще пытаюсь получить видео для воспроизведения в моем приложении - PullRequest
0 голосов
/ 25 января 2012

Хорошо, поэтому я не смог правильно опубликовать свой код в прошлый раз ... Я новичок. Я немного изменил вещи, и я пытаюсь заставить видео воспроизводиться из 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

Ответы [ 2 ]

0 голосов
/ 25 января 2012

Вы добавили свой файл "WhatFinalTake.mp4" в свой проект?

Я нашел следующее полезное в воспроизведении видео, вы можете вызвать это из своего tableView:

http://iosdevelopertips.com/video/getting-mpmovieplayercontroller-to-cooperate-with-ios4-3-2-ipad-and-earlier-versions-of-iphone-sdk.html

Я считаю, что полезно зарегистрироваться для уведомлений LoadStateChanged или PreloadDidFinish (в зависимости от версии iOS) и выполнить фактическое воспроизведение оттуда, чтобы убедиться, что видео подготовлено.Вы можете узнать, как это сделать, по ссылке выше.Поскольку он сделал все для вас, я рекомендую просто использовать предоставленный код.

0 голосов
/ 25 января 2012

Я проверил ваш код и обнаружил, что ваша строка filePath равна nil.Попробуйте это:

NSString *filepath = [NSString stringWithFormat:@"%@",[[NSBundle mainBundle] pathForResource:@"WhatFinalTake" ofType:@"mp4"]];  
NSLog(@"%@",filepath);
NSURL    *fileURL = [NSURL fileURLWithPath:filepath];  
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...