gpt4 book ai didi

ios - 如何停止/播放视频

转载 作者:行者123 更新时间:2023-11-29 04:43:18 25 4
gpt4 key购买 nike

#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能帮助我。提前致谢。

最佳答案

你给了 scrollView.contentSize = CGSizeMake(4096, 768); 这意味着当你滚动时 View 不会消失或出现。滚动将按位置消失或出现。实际上滚动是打开的所以,你需要在滚动时控制视频的停止和播放。所以,你给播放器框架,当滚动移动位置出现播放器位置时播放它。当穿过播放器时帧停止它。在带有 if else 条件的 scrollViewDidScroll 方法中执行此播放和停止代码。

关于ios - 如何停止/播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10036537/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com