Iphone MPMoviePlayerLoadStateDidChangeNotification不是';我没打电话

Iphone MPMoviePlayerLoadStateDidChangeNotification不是';我没打电话,iphone,ios4,mpmovieplayercontroller,Iphone,Ios4,Mpmovieplayercontroller,我正在将iOS3应用程序转换为iOS4,并且电影播放器出现问题!我遵循了(我不再需要它在iOS3中工作!),并使用以下代码将UIViewController子类化: #import "moviePlayer.h" @implementation moviePlayer @synthesize mainAppDelegate; @synthesize mp; - (id)initWithMovie:(NSString *)moviePath delegate:(id)delegate {

我正在将iOS3应用程序转换为iOS4,并且电影播放器出现问题!我遵循了(我不再需要它在iOS3中工作!),并使用以下代码将UIViewController子类化:

#import "moviePlayer.h"

@implementation moviePlayer
@synthesize mainAppDelegate;
@synthesize mp;

- (id)initWithMovie:(NSString *)moviePath delegate:(id)delegate {
    self.mainAppDelegate = delegate;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:mainAppDelegate selector:@selector(movieFinishedPlaying:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

    self.mp =  [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:moviePath]];
    [mp setControlStyle:MPMovieControlStyleFullscreen];
    [mp setShouldAutoplay:YES];

    return self;
}

- (void) moviePlayerLoadStateChanged:(NSNotification*)notification {

    NSLog(@"moviePlayerLoadStateChanged");

    // Unless state is unknown, start playback
    if ([mp loadState] != MPMovieLoadStateUnknown) {

        // Remove observer
        [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

        //Set Landscape and Rotate
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
        [[self view] setBounds:CGRectMake(0, 0, 480, 320)];
        [[self view] setCenter:CGPointMake(160, 240)];
        [[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];

        //Set frame, add view and play
        [[mp view] setFrame:CGRectMake(0, 0, 480, 320)];
        [[self view] addSubview:[mp view]];
        [mp play];

        //Tell main app that it worked!
        [mainAppDelegate performSelector:@selector(movieLoaded:) withObject:mp];

    } else if ([mp loadState] == MPMovieLoadStateUnknown) {
        [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
        [mainAppDelegate performSelector:@selector(movieLoaded:) withObject:nil];
    }

}

- (void)dealloc {
    [mainAppDelegate release];
    [mp release];
    [super dealloc];
}

@end
moviePath
是已下载并保存到设备上的本地文件

问题是,
moviePlayerLoadStateChanged
有时不会被调用。如果文件是下载的,然后每次从它工作的设备播放,如果我尝试从保存的位置播放文件,它不会被调用-我可以听到电影声音,但看不到它,因为没有播放的视图


我使用了
NSLog(@“%@”,moviePath)在init顶部查看差异,没有-URL(本地路径)是相同的吗

我知道这个问题已经很老了,但是谷歌把我带到这里来的时候,我正在查找其他的东西。因为没有答案,其他人可能会想知道

MPMoviePlayerLoadStateDidChangeNotification

仅在网络回迁期间专门调用。根据苹果公司的文件:

当电影播放器的网络缓冲状态发生更改时发布。没有用户信息字典

要检索电影播放器的当前加载状态,请访问其loadState属性。状态已更改的电影播放器可用作与通知关联的对象


同样,OP的问题是,只有在下载相关文件时才会触发通知,这一问题正按照苹果的预期发挥作用。

如果提供链接,还需要提供上下文。如果这一联系中断,你的问题的背景也会中断。