gpt4 book ai didi

ios - MPMoviePlayerController initWithContentURL 延迟按钮点击

转载 作者:行者123 更新时间:2023-11-29 01:41:43 26 4
gpt4 key购买 nike

我有一个 for 循环来加载 MPMoviePlayerController 中的一些视频,但当用户单击 backButton 时我需要停止它。仅当电影加载完成时才会检测到单击事件。我该如何解决?

这是我的方法,其中包含循环

-(void) criarScrollMidias:(Evento *)evento {
NSLog(@"criar scroll midias");

NSMutableArray *listaImagens = evento.atracao.images;
NSMutableArray *listaVideos = evento.atracao.videos;

if([listaVideos count] > 0) {
self.listaVideoPlayers = [[NSMutableArray alloc]init];
}

[self.scrollImVd setPagingEnabled:YES];

if(![self.eventoAtual.atracao.imageLarge isKindOfClass:[NSNull class]])
{

UIImageView *imgViewAtracao = [[UIImageView alloc]initWithImage:self.eventoAtual.atracao.imageLarge];
[imgViewAtracao setContentMode:UIViewContentModeScaleAspectFit];
[imgViewAtracao setFrame:CGRectMake(0, 0, self.scrollImVd.frame.size.width, self.scrollImVd.frame.size.height)];
[self.scrollImVd addSubview:imgViewAtracao];
}

for (int iCnt = 0; iCnt < [listaImagens count]; iCnt++) {
NSString *imgURL = [listaImagens objectAtIndex:iCnt];
UIImage *imagemAtracao = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imgURL]]];
UIImageView *imgViewAtracao = [[UIImageView alloc]initWithImage:imagemAtracao];

[imgViewAtracao setContentMode:UIViewContentModeScaleAspectFit];
if(![self.eventoAtual.atracao.imageLarge isKindOfClass:[NSNull class]])
[imgViewAtracao setFrame:CGRectMake(0+self.scrollImVd.frame.size.width*(iCnt+1), 0, self.scrollImVd.frame.size.width, self.scrollImVd.frame.size.height)];
else
[imgViewAtracao setFrame:CGRectMake(0+self.scrollImVd.frame.size.width*iCnt, 0, self.scrollImVd.frame.size.width, self.scrollImVd.frame.size.height)];

[self.scrollImVd addSubview:imgViewAtracao];
}

for (int iCnt = 0; iCnt < [listaVideos count]; iCnt++) {
NSString *videoURLStr = [listaVideos objectAtIndex:iCnt];
NSURL *videoURL = [NSURL URLWithString:videoURLStr];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayer setShouldAutoplay:NO];
[moviePlayer.view setBackgroundColor:[UIColor colorWithPatternImage:[self gerarPreviewVideo:videoURL]]];

CGFloat posicaoInicial = 0.0;
if(![self.eventoAtual.atracao.imageLarge isKindOfClass:[NSNull class]])
posicaoInicial = self.scrollImVd.frame.size.width * ([listaImagens count] + 1);
else
posicaoInicial = self.scrollImVd.frame.size.width * [listaImagens count];

[moviePlayer.view setFrame:CGRectMake(posicaoInicial+self.scrollImVd.frame.size.width*iCnt, 0, self.scrollImVd.frame.size.width, self.scrollImVd.frame.size.height)];

UIButton *playButton = [[UIButton alloc] initWithFrame:CGRectMake(moviePlayer.view.frame.origin.x+(self.scrollImVd.frame.size.width/2)-34, moviePlayer.view.frame.origin.y+(self.scrollImVd.frame.size.height/2)-33, 67, 66)];
[playButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
playButton.tag = iCnt;
[playButton addTarget:self action:@selector(playButtonClick:) forControlEvents:UIControlEventTouchUpInside];

[self.scrollImVd addSubview:moviePlayer.view];
[self.scrollImVd addSubview:playButton];
[self.listaVideoPlayers addObject:moviePlayer];
}

if(![self.eventoAtual.atracao.imageLarge isKindOfClass:[NSNull class]])
[self.scrollImVd setContentSize:CGSizeMake(self.scrollImVd.frame.size.width * ([listaImagens count] + [listaVideos count] + 1), self.scrollImVd.frame.size.height)];
else
[self.scrollImVd setContentSize:CGSizeMake(self.scrollImVd.frame.size.width * ([listaImagens count] + [listaVideos count]), self.scrollImVd.frame.size.height)];
[self.viewLoading setHidden:YES];
}

还有按钮点击事件:

-(IBAction)btnVoltarClick:(id)sender {
[self.playerVideo stop];
[self transicaoVoltar];
[self.presentingViewController dismissViewControllerAnimated:NO completion:nil];
}

我在 btnVoltarClick 事件中放置了一个断点,并且仅当方法 criarScrollMidias 时才会触发该断点

完成

最佳答案

我解决了在新线程中调用 criarScrollViewMidias 的问题

 [NSThread detachNewThreadSelector:@selector(criarScrollMidias:) toTarget:self withObject:self.eventoAtual];

关于ios - MPMoviePlayerController initWithContentURL 延迟按钮点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32318790/

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