2013-09-27 4 views
1

cocos2d에서 .mp4 비디오를 재생하려고합니다. 아래 내 코드를 참조하십시오. 비디오가 재생되지 않고 화면의 1/3을 차지하는 검정색 배경 만 나타납니다.Cocos2d .mp4 비디오가 재생되지 않습니다.

Instructions.m :

#import "Instructions.h" 

@implementation Instructions 

- (id)init 
{ 
    self = [super init]; 
    if (self != nil) 
    { 
     [self playInstructionsVideo]; 
    } 
    return self; 
} 

- (void)playInstructionsVideo 
{ 
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Instructions" ofType:@"mp4"]]; 
    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 

    // Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlayBackDidFinish:) 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:moviePlayer]; 

    if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) 
    { 
     // Use the new 3.2 style API 
     moviePlayer.controlStyle = MPMovieControlStyleNone; 
     moviePlayer.shouldAutoplay = YES; 
     // This does blows up in cocos2d, so we'll resize manually 
     // [moviePlayer setFullscreen:YES animated:YES]; 
     [moviePlayer.view setTransform:CGAffineTransformMakeRotation((float)M_PI_2)]; 
     CGSize winSize = [[CCDirector sharedDirector] winSize]; 
     moviePlayer.view.frame = CGRectMake(0, 0, winSize.height, winSize.width); // width and height are swapped after rotation 
     [[[CCDirector sharedDirector] view] addSubview:moviePlayer.view]; 
    } 
    else 
    { 
     // Use the old 2.0 style API 
     moviePlayer.controlStyle = MPMovieControlStyleNone; 
     [moviePlayer play]; 
    } 
} 

- (void)moviePlayBackDidFinish:(NSNotification *)notification 
{ 
    MPMoviePlayerController *moviePlayer = [notification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                name:MPMoviePlayerPlaybackDidFinishNotification 
                object:moviePlayer]; 

    // If the moviePlayer.view was added to the openGL view, it needs to be removed 
    if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) 
    { 
     [moviePlayer.view removeFromSuperview]; 
    } 

    [moviePlayer release]; 
} 

@end 

이 제발 도와주세요, 나는 비정상적인 행동 원인을 모르겠습니다.

+0

무비 프레임 크기를 설정하기 전에 winSize.height 및 winSize.width는 무엇입니까? –

+0

@MichaelDautermann : 죄송합니다. 귀하의 의견을 일찌감치 보지 못했습니다. 비디오를 재생할 수 있었지만 방향은 화면의 왼쪽 절반을 향하고 있습니다 ([스크린 샷 참조] (http://imgur.com/4IekvPa)). CCLOG를 넣어서 winSize.width와 winSize.height를 확인하고 너비와 높이가 각각 568.0과 320.0을 얻었습니다. 이 문제를 어떻게 해결할 수 있습니까? – NSologistic

답변

2

방금이 코드를 복사했다고 생각합니다. 어쨌든 스크린 샷에서 방향 변경이 setTransform의 결과임을 분명히합니다. 줄 제거

[moviePlayer.view setTransform:CGAffineTransformMakeRotation((float)M_PI_2)]; 

방향 문제를 해결해야합니다.

관련 문제