1

经过漫长的一天研究为什么 1024x768 视频无法在 iPad 3 上运行,以及大量的论坛搜索。我找不到任何合理的解决方案来解决这个问题。似乎很多人都有同样的情况,只显示黑屏。

解决方案是将所需的视频渲染为 1024x 748。原因是 iPad 顶部显示的状态栏是 20px。

我希望这可以解决他们在这种情况下遇到的很多用户问题。

进入我的下一个问题......

我目前通过 MPMoviePlayerController 将视频嵌入到我的视图中。该视频在不断循环中(动画菜单)。然后,我在调用方法的视频顶部放置了三个不可见的按钮。我目前只有一个工作,另外两个只是显示警报。

我目前遇到的问题是,当单击按钮时,我想要播放另一个视频。这是完美的工作,但我希望第一个视频首先播放到最后,然后继续播放下一个视频,原因是,我也需要它是无缝的,并且从一个视频到另一个视频不明显。

对此的任何反馈都会很棒....

#import "MainViewController.h"
#import "VideoPlayerViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#import <UIKit/UIKit.h>

@interface MainViewController () 

@property (nonatomic, retain) MPMoviePlayerController *playerViewController;
@property (nonatomic, retain) VideoPlayerViewController *myPlayerViewController;

@end


@implementation MainViewController

@synthesize playerViewController = _playerViewController;
@synthesize myPlayerViewController = _myPlayerViewController;

- (void)dealloc {
    self.playerViewController = nil;
    self.myPlayerViewController = nil;

    [super dealloc];
}


#pragma mark - View lifecycle

-(void)buttonEventOne:(id)sender {

    //[[[[UIAlertView alloc] initWithTitle:@"CONTENT ONE" message:@"This will link to content one video" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease] show];


    NSURL *urlTwo = [[NSBundle mainBundle] URLForResource:@"BAE_BG_anim_pt2_748" withExtension:@"mov"];
    MPMoviePlayerController *playerViewController = [[MPMoviePlayerController alloc] init];

    playerViewController.contentURL = urlTwo;
    playerViewController.view.frame = CGRectMake(0, 0, 1024, 768);
    playerViewController.controlStyle = MPMovieControlStyleNone;
    //playerViewController.repeatMode = MPMovieRepeatModeOne;

    [self.view addSubview:playerViewController.view];
    [playerViewController play];

    self.playerViewController = playerViewController;
    [playerViewController release];


}

-(void)buttonEventTwo:(id)sender {

    [[[[UIAlertView alloc] initWithTitle:@"CONTENT TWO" message:@"This will link to content one video" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease] show];
}

-(void)buttonEventThree:(id)sender {

    [[[[UIAlertView alloc] initWithTitle:@"CONTENT THREE" message:@"This will link to content one video" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease] show];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"BAE_Main_Loop_748" withExtension:@"mov"];

    // video player
    MPMoviePlayerController *playerViewController = [[MPMoviePlayerController alloc] init];
    playerViewController.contentURL = url;
    [playerViewController prepareToPlay];
    playerViewController.view.frame = CGRectMake(0, 0, 1024, 768);
    playerViewController.controlStyle = MPMovieControlStyleNone;
    playerViewController.repeatMode = MPMovieRepeatModeOne;

    [self.view addSubview:playerViewController.view];
    [playerViewController play];

    self.playerViewController = playerViewController;
    [playerViewController release];

    UIButton * btnOne = [UIButton buttonWithType:UIButtonTypeCustom];
    btnOne.frame = CGRectMake(260, 350, 150, 50);
    [btnOne setTitle:@"" forState:UIControlStateNormal];
    [btnOne addTarget:self action:@selector(buttonEventOne:)forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnOne];

    UIButton * btnTwo = [UIButton buttonWithType:UIButtonTypeCustom];
    btnTwo.frame = CGRectMake(620, 350, 150, 50);
    [btnTwo setTitle:@"" forState:UIControlStateNormal];
    [btnTwo addTarget:self action:@selector(buttonEventTwo:)forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnTwo];

    UIButton * btnThree = [UIButton buttonWithType:UIButtonTypeCustom];
    btnThree.frame = CGRectMake(450, 250, 150, 50);
    [btnThree setTitle:@"" forState:UIControlStateNormal];
    [btnThree addTarget:self action:@selector(buttonEventThree:)forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btnThree];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || 
            interfaceOrientation == UIInterfaceOrientationLandscapeRight);
} 
@end
4

1 回答 1

0

您是否尝试过注册播放通知,特别是MPMoviePlayerPlaybackDidFinishNotification吸引人的吧?如果您在按下按钮时注册通知:

[[NSNotificationCenter defaultCenter] 
  addObserver:self 
  selector:@selector(introMovieFinished:) 
  name:MPMoviePlayerPlaybackDidFinishNotification 
  object:self.playerViewController];

然后在那个函数中:

- (void)introMovieFinished:(NSNotification*)note {
  [[NSNotificationCenter defaultCenter] 
    removeObserver:self 
    name:MPMoviePlayerPlaybackDidFinishNotification
    object:self.playerViewController];
  // Do stuff.
}

您取消注册您对通知的兴趣,然后开始播放下一部电影。因为您仅在按下按钮时才注册兴趣,所以在电影结束之前您不应该收到函数调用。

于 2012-04-23T14:51:58.900 回答