2012-04-05 186 views
0
#import "ViewController.h" 

@implementation ViewController 
@synthesize scrollView; 

- (void)viewDidLoad 
{ 
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO]; 

    [self.view addSubview:scrollView]; 
    scrollView.contentSize = CGSizeMake(4096, 768); 


    NSString *url = [[NSBundle mainBundle] pathForResource:@"F0" ofType:@"mov"]; 

    player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(movieFinishedCallback) 
              name:MPMoviePlayerPlaybackDidFinishNotification 
              object:player]; 
    player.view.frame = CGRectMake(0, 0, 1024, 768); 
    player.scalingMode = MPMovieScalingModeAspectFill; 
    [scrollView addSubview:player.view]; 
    [player play]; 

    UIImageView *image1 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"29-30-p1.jpg"]]; 
    image1.frame = CGRectMake(1024,0,1024,768); 
    image1.clipsToBounds = YES; 
    [scrollView addSubview:image1]; 
    image1.animationImages = eyeFrames; 
    image1.animationDuration = 0.25; 
    image1.animationRepeatCount = 1; 

    UIImageView *image2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"29-30-p2.jpg"]]; 
    image2.frame = CGRectMake(2048,0,1024,768); 
    image2.clipsToBounds = YES; 
    [scrollView addSubview:image2]; 

    UIImageView *image3 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"29-30-p3.jpg"]]; 
    image3.frame = CGRectMake(3072,0,1024,768); 
    image3.clipsToBounds = YES; 
    [scrollView addSubview:image3]; 


    [super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
} 

- (void) movieFinishedCallback:(NSNotification *) aNotification{ 
    MPMoviePlayerController *moviePlayer = [aNotification object]; 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
              name:MPMoviePlayerPlaybackDidFinishNotification 
              object:moviePlayer]; 
    [moviePlayer.view removeFromSuperview]; 
    [player release]; 

} 

-(void)viewWillDisappear:(BOOL)animated{ 

    //NSLog(@"x=%f",scrollView.contentOffset.x); 
    [player stop]; 

} 

-(void)viewWillAppear:(BOOL)animated{ 
    [player play]; 
} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
    // Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return YES; 
} 

@end 

,大家好,我不知道爲什麼viewWillDisappearviewWillAppear循環是行不通的。如果我滾動並在回滾時繼續播放,我想停止播放視頻。讓我知道爲什麼它不工作。順便說一句,我不知道爲什麼當視頻結束時程序終止。我在前面的項目中使用了相同的代碼,並且沒有顯示任何錯誤。我有點困惑。希望some1能幫助我。提前致謝。如何停止/播放視頻

回答

1

U給了scrollView.contentSize = CGSizeMake(4096, 768);這意味着當你滾動時視圖不會消失或出現。滾動將定位明智地消失或出現。實際上滾動是在視圖上。所以你需要在視圖停止和播放時滾動。所以,你給幀player,當滾動移動位置出現在播放器位置然後播放它。當穿過播放器幀停止它。這個播放和停止代碼在scrollViewDidScroll方法與if else條件。