MPMoviePlayerViewController并捏出全屏

时间:2010-11-10 11:38:11

标签: iphone objective-c ipad mpmovieplayercontroller

我在网站上搜索但我没有找到与我相同的问题

当我对我的视频进行捏合时,会调用通知“MPMoviePlayerPlaybackDidFinishNotification”。

之后,“完成”按钮暂停视频并且播放器工作正常......

我不明白为什么要通知这个通知......

这是我的代码

    - (id) init
{
    self = [super init];

    movie=[[MPMoviePlayerViewController alloc] init]; 
    //we init the frame here and after the view rotate the video
    [movie.view setFrame: CGRectMake(0, 0, 1024,768)];

    return self;
}

+ (MoviePlayerManager*) getInstance
{

    static MoviePlayerManager *movieSingleton;

    if (movieSingleton==nil) 
    {
        movieSingleton = [[MoviePlayerManager alloc]init];

    }

    return movieSingleton;

}

- (void) load:(NSURL*) a_videoFile withType:(VideoType)a_type
{

    type = a_type;

    [movie.moviePlayer setContentURL:a_videoFile];

        switch (type) {
        case VT_INTRO:
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallbackIntro:) name:MPMoviePlayerPlaybackDidFinishNotification object:movie.moviePlayer]; 
            break;

        case VT_RESPONSE:
            [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallbackResponse:) name:MPMoviePlayerPlaybackDidFinishNotification object:movie.moviePlayer]; 
            break;

        default:
            NSLog(@"video Type not initialised");
            break;
    }

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieIsReadyToPlay:) name:MPMediaPlaybackIsPreparedToPlayDidChangeNotification object:movie.moviePlayer]; 


    [movie.moviePlayer prepareToPlay];


}


-(void)myMovieIsReadyToPlay:(NSNotification*)aNotification 
{
    [gsDelegate.view addSubview:movie.view];
    [movie.moviePlayer play]; 

    movie.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;

}

- (void) myMovieFinishedCallbackIntro:(NSNotification*)aNotification 
{
    NSNumber* reason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];

    NSLog(@"%d",reason);

    if(aNotification != nil)
    {

        [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:movie.moviePlayer];

        [gsDelegate movieIntroDidStop];

    }
}

NSNumber* reason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];

对于捏合或按“完成”

是相同的

thx求助(对不起我的英文不好; op)

1 个答案:

答案 0 :(得分:0)

NSNumber* reason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey]; 
NSLog(@"%d",reason);

NSNumber是Objective-C对象,而不是原始C类型。您正在显示指向对象的指针,而不是值。

纠正:

NSLog(@"%@", reason);

或将原因更改为整数:

int reason = [[userInfo objectForKey:@"MPMoviePlayerPlaybackDidFinishReasonUserInfoKey"] intValue];
NSLog(@"%d", reason);