MPMoviePlayerPlaybackDidFinishNotification не вызывается - PullRequest
1 голос
/ 06 мая 2011

Здесь, в моем коде, playerPlayBackDidFinish не вызывается при нажатии кнопки «Далее» и кнопки «Назад» на верхней панели. но он вызывается, когда видео файл воспроизводится полностью, пожалуйста, помогите, если кто-нибудь знает ...

Мой код выглядит следующим образом.

#import "seq_nineViewController.h"

@implementation seq_nineViewController

@synthesize ninethVideoController, Bean;
@synthesize localBackFlag;
@synthesize goingNextButton, goingBackButton;

- (void) viewWillAppear:(BOOL)animated {

        //[super viewWillAppear];
    appDelegate = (wishstix_appAppDelegate *) [[UIApplication sharedApplication] delegate];
    appDelegate.backFlag = 0;
    self.localBackFlag = 0;

    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.hidesBackButton = YES;

    goingNextButton =[[UIBarButtonItem alloc] init];
    goingNextButton.title=@"Next";
    goingNextButton.target=self;
    goingNextButton.action=@selector(nextAction);
    self.navigationItem.rightBarButtonItem=goingNextButton;
    [goingNextButton release];

    goingBackButton =[[UIBarButtonItem alloc] init];
    goingBackButton.title=@"Back";
    goingBackButton.target=self;
    goingBackButton.action=@selector(backAction);
    self.navigationItem.leftBarButtonItem=goingBackButton;
    [goingBackButton release];


    NSEnumerator *AplicationEnumerator  = [[appDelegate.categoryDictionary objectForKey:[appDelegate.categoryArray objectAtIndex:appDelegate.categoryRowId]] reverseObjectEnumerator];
    NSArray *array = [AplicationEnumerator allObjects];
    NSArray *arr = [[NSArray alloc] initWithArray:array];

    self.Bean = [arr objectAtIndex:appDelegate.appLicationRowId];

    MediaVideoPostUIBean *seq9_asset = [[[self.Bean aplicationFlow] arrayOfMediaVideoPostUI]objectAtIndex:2];

    if  ([[seq9_asset skip] isEqualToString:skipValueFalse]) {
        NSMutableString *url = [[NSMutableString alloc] init];
        [url appendString:[appDelegate.rootBean RootFileLocation]];
        if (appDelegate.avatarFlag == 1)
            [url appendString:[seq9_asset srcUrlMale]];
        else if (appDelegate.avatarFlag == 2)
            [url appendString:[seq9_asset srcUrlFemale]];

        [appDelegate showActivityViewer];
        self.ninethVideoController = [self getVideo:url];

        if (self.ninethVideoController == nil) {
            appDelegate.viewNumber = 15;
            ControllerClass *temp = [[ControllerClass alloc] init];
            [temp changeViewControllers];

        } else {

            self.goingNextButton.enabled = NO;
            self.goingBackButton.enabled = NO;

            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ninthMoviePlayerPlaybackDidFinish) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; // self.ninethVideoController]; 
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ninthPlayerLoadState) name:MPMoviePlayerLoadStateDidChangeNotification object:self.ninethVideoController]; 
            [self.view addSubview:self.ninethVideoController.view];
            [self.ninethVideoController play];

            [url release];

        }       
    }
    else if ([[seq9_asset skip] isEqualToString:skipValueTrue]) {
        appDelegate.viewNumber = 15;
        ControllerClass *temp = [[ControllerClass alloc] init];
        [temp changeViewControllers];
    }

}


- (MPMoviePlayerController*)getVideo:(NSString *)url {

    NSLog(@"Inside the getVideo of ninthMoviePlayer");
    [url retain];
    NSURL *fileURL = [NSURL URLWithString:url];
    MPMoviePlayerController *moviePlayerController = [[[MPMoviePlayerController alloc] initWithContentURL:fileURL] autorelease];  
    if (([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeRight) || ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationLandscapeLeft))
        moviePlayerController.view.frame = CGRectMake(0.0, 0.0, 480.0, 280.0);
    else
        moviePlayerController.view.frame = CGRectMake(0.0, -35.0, 320.0, 436.0);
    [url release];
    return moviePlayerController;
}


- (void) ninthMoviePlayerPlaybackDidFinish {

    NSLog(@"Inside the ninthPlayerPlaybackDidFinish");
    [self.ninethVideoController.view removeFromSuperview];  
    self.ninethVideoController = nil;

    if (self.localBackFlag == 1) {
        [self.navigationController popViewControllerAnimated:YES];

    } else {

    appDelegate.viewNumber = 15;
    ControllerClass *control = [[ControllerClass alloc] init];
    [control changeViewControllers];
    }
}


- (void) ninthPlayerLoadState{

    [appDelegate hideActivityViewer];
    self.goingNextButton.enabled = YES;
    self.goingBackButton.enabled = YES;
}


// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    if ((interfaceOrientation == UIInterfaceOrientationLandscapeRight) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)) {

        NSLog(@"enterd landscape");
        [self.ninethVideoController.view removeFromSuperview];
        self.ninethVideoController.view.frame  = CGRectMake(0.0, 0.0, 480.0, 280.0);
        [self.view addSubview:self.ninethVideoController.view];

    } else if (interfaceOrientation == UIInterfaceOrientationPortrait) {

        NSLog(@"entered portrait");
        [self.ninethVideoController.view removeFromSuperview];
        self.ninethVideoController.view.frame  = CGRectMake(0.0, -35.0, 320.0, 436.0);
        [self.view addSubview:self.ninethVideoController.view];

    } else if (interfaceOrientation == UIDeviceOrientationPortraitUpsideDown) {

        NSLog(@"entered PortraitUpsideDown");
        [self.ninethVideoController.view removeFromSuperview];
        self.ninethVideoController.view.frame = CGRectMake(0.0, -20.0, 320.0, 436.0);
        [self.view addSubview:self.ninethVideoController.view];

    }   
    return (YES);

}


- (IBAction) nextAction {

    NSLog(@"Inside the nextAction of ninthVideoPlayer");
    appDelegate.backFlag = 0;
    self.localBackFlag = 0;
    [self.ninethVideoController stop];
    NSLog(@"After executing stop statememt");
    //[self ninthPlayerPlaybackDidFinish];
}

- (IBAction) backAction {

    NSLog(@"Inside the backAction of ninthVideoPlayer");
    appDelegate.backFlag = 1;
    self.localBackFlag = 1;
    //[self.ninethVideoController pause];
    [self.ninethVideoController stop];
    //[self ninthPlayerPlaybackDidFinish];
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}


- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
    self.ninethVideoController = nil;
}

@end

Ответы [ 3 ]

4 голосов
/ 06 мая 2011

Вы читали это

MPMoviePlayerPlaybackDidFinishNotification

Уведомляет зрителей о завершении воспроизведения фильма.Уязвимый проигрыватель фильмов сохраняется в параметре объекта уведомления.Словарь userInfo этого уведомления содержит ключ MPMoviePlayerPlaybackDidFinishReasonUserInfoKey, который указывает причину завершения воспроизведения.Это уведомление также отправляется при сбое воспроизведения из-за ошибки.

Это уведомление не отправляется в тех случаях, когда проигрыватель фильмов отображается в полноэкранном режиме, а пользователь нажимает кнопку Готово.В этом случае кнопка «Готово» останавливает воспроизведение фильма, когда проигрыватель выходит из полноэкранного режима.Если вы хотите обнаружить этот сценарий в своем коде, вам следует отслеживать другие уведомления, такие как MPMoviePlayerDidExitFullscreenNotification.

Убедитесь, что вы не делаете ничего, что не отправило это уведомление

1 голос
/ 10 сентября 2015

У меня была похожая проблема, и я обнаружил, что установка repeatMode для MPMoviePlayerController в MPMovieRepeatModeOne останавливает MPMoviePlayerPlaybackDidFinishNotification от запуска, который я должен был сделать для воспроизведения видео в цикле.

MPMoviePlayerController *moviePlayer =     [[MPMoviePlayerController alloc] initWithContentURL:video_url];
[moviePlayer setRepeatMode:MPMovieRepeatModeOne];

Когда я изменил repeatMode в MPMoviePMineNove_Mlay_PlayerNoveMonePlayerMonePlayerвыстрелил правильно.

1 голос
/ 11 января 2013

соблюдать

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(movieDidExitFullscreen:)
                                                 name:MPMoviePlayerDidExitFullscreenNotification
                                               object:nil];

и добавить действие

- (IBAction) movieDidExitFullscreen:(NSNotification*)notification
    {
        NSLog(@"movieDidExitFullscreen");
        [self.moviePlayer stop];
        [self.moviePlayer setFullscreen:NO animated:NO];
        [self.moviePlayer.view removeFromSuperview];
    }
...