未调用MPMoviePlayerLoadStateDidChangeNotification

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了未调用MPMoviePlayerLoadStateDidChangeNotification相关的知识,希望对你有一定的参考价值。

我正在将我的ios3应用程序转换为iOS4并且遇到电影播放器​​问题!我已经关注了the example here(我不再需要它在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有时不会被调用。如果文件被下载然后从设备播放它每次都有效,如果我尝试从其保存的位置播放文件它没有被调用 - 我可以听到电影声音,但是看不到它,因为没有视图它可以玩!

我在init的顶部使用了NSLog(@"%@", moviePath);来查看差异并且没有 - URL(本地路径)是相同的哪个?!

答案

我知道这个问题已经很老了,但谷歌把我带到了这里看了别的东西。由于没有答案,而其他人可能会想,

MPMoviePlayerLoadStateDidChangeNotification

仅在网络提取期间被称为ONLY。根据Apple的文档:

当电影播放器​​的网络缓冲状态发生变化时发布。没有userInfo字典。

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

因此,OP的问题,即仅在下载有问题的文件时触发的通知的问题,正如Apple所预期的那样起作用。

以上是关于未调用MPMoviePlayerLoadStateDidChangeNotification的主要内容,如果未能解决你的问题,请参考以下文章

numberOfRowsInSection 已调用但 cellForRowAt 未调用

调用 textFieldShouldBeginEditing,未调用 textFieldDidBeginEditing

JQuery:未捕获的类型错误:无法读取未定义的属性“调用”

调用结果未使用

C# Web Api 调用未从 jquery 调用

未调用 cellForRowAtIndexPath 但调用 numberOfRowsInSection