Video Cocos2d.mp4视频未播放
我正在尝试在cocos2d中播放.mp4视频。请看下面我的代码。视频没有播放,只有一个黑色背景覆盖了屏幕的三分之一多一点 说明.m:Video Cocos2d.mp4视频未播放,video,cocos2d-iphone,mpmovieplayercontroller,Video,Cocos2d Iphone,Mpmovieplayercontroller,我正在尝试在cocos2d中播放.mp4视频。请看下面我的代码。视频没有播放,只有一个黑色背景覆盖了屏幕的三分之一多一点 说明.m: #import "Instructions.h" @implementation Instructions - (id)init { self = [super init]; if (self != nil) { [self playInstructionsVideo]; } return self; }
#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
请帮帮我,我不确定是什么导致了这种异常行为。我感觉你刚刚复制了这段代码。无论如何,从屏幕截图可以清楚地看出,方向的改变是setTransform的结果。删除线路
[moviePlayer.view setTransform:CGAffineTransformMakeRotation((float)M_PI_2)];
应该可以解决方向问题。在设置电影帧大小之前,winSize.height和winSize.width是什么?@MichaelDautermann:对不起,我没有提前看到你的评论。我已经能够播放视频,但方向是面向屏幕的左半部分()。我放了一个CCLOG来检查winSize.width和winSize.height,分别得到了568.0和320.0的宽度和高度。我如何解决这个问题?