未调用MPMoviePlayerPlaybackDidFinishNotification [英] MPMoviePlayerPlaybackDidFinishNotification not being called

查看:82
本文介绍了未调用MPMoviePlayerPlaybackDidFinishNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,在点击TopBar上的nextbutton和backButton时,不会调用pl​​ayerPlayBackDidFinish。但是当完整播放视频文件时会调用它,如果有人知道请帮助...

Here in my code playerPlayBackDidFinish is not called upon clicking the nextbutton and backButton on TopBar. but it is called when the video file is played completly, please help if anybody know...

我的代码如下。

#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


推荐答案

你读过这个吗?


MPMoviePlayerPlaybackDidFinishNotification

通知观察者电影
已完成播放。受影响的电影
播放器存储在通知的对象
参数中。此
通知的
userInfo字典包含
MPMoviePlayerPlaybackDidFinishReasonUserInfoKey
键,表示
播放完成的原因。当播放因错误而导致
失败时,也会发送此通知

Notifies observers that the movie finished playing. The affected movie player is stored in the object parameter of the notification. The userInfo dictionary of this notification contains the MPMoviePlayerPlaybackDidFinishReasonUserInfoKey key, which indicates the reason that playback finished. This notification is also sent when playback fails because of an error.

如果电影
,则不会发送此通知播放器在全屏模式下显示
,用户点击完成按钮
。在这种情况下,
完成按钮会导致电影播放暂停,然后播放器转换为全屏模式的
。如果你想在你的代码中检测
这种情况​​,你
应该监控其他通知
,例如
MPMoviePlayerDidExitFullscreenNotification。

This notification is not sent in cases where the movie player is displaying in fullscreen mode and the user taps the Done button. In that instance, the Done button causes movie playback to pause while the player transitions out of fullscreen mode. If you want to detect this scenario in your code, you should monitor other notifications such as MPMoviePlayerDidExitFullscreenNotification.

确保您没有做任何未发送此通知的事情

Make sure that you are not doing anything that does not sent this notification

这篇关于未调用MPMoviePlayerPlaybackDidFinishNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆