Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/flash/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 音频会话在新线程中崩溃_Ios_Objective C_Multithreading_Uiscrollview_Avaudiosession - Fatal编程技术网

Ios 音频会话在新线程中崩溃

Ios 音频会话在新线程中崩溃,ios,objective-c,multithreading,uiscrollview,avaudiosession,Ios,Objective C,Multithreading,Uiscrollview,Avaudiosession,我有一个方法,可以通过编程方式创建UIScrollView和子视图。您的一个视图是MoviewPlayer…在创建scrollview时,我需要允许用户退出屏幕(在加载结束之前)。然后,我在另一个NSThread中调用了这个方法 但是我得到了以下错误: [\uu NSCFData\u pickableRoutesDidChangeNotification:]:发送到实例的选择器无法识别 我认为不可能在另一个线程中完成。那么,如何允许用户在加载结束之前退出视图 这是我的密码: -(void) vi

我有一个方法,可以通过编程方式创建UIScrollView和子视图。您的一个视图是MoviewPlayer…在创建scrollview时,我需要允许用户退出屏幕(在加载结束之前)。然后,我在另一个NSThread中调用了这个方法

但是我得到了以下错误:

[\uu NSCFData\u pickableRoutesDidChangeNotification:]:发送到实例的选择器无法识别

我认为不可能在另一个线程中完成。那么,如何允许用户在加载结束之前退出视图

这是我的密码:

-(void) viewDidAppear:(BOOL)animated {
    [NSThread detachNewThreadSelector:@selector(criarScrollMidias:) toTarget:self withObject:self.eventoAtual];
}

-(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.movieSourceType = MPMovieSourceTypeStreaming;
    [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];

   }

我该怎么解决呢

是您的方法pickableRoutesDidChangeNotification吗?如果是,则它将作为NSData方法调用。您的错误显示该方法不是NSData方法。@johnykumar pickableRoutesDidChangeNotification是来自MPMoviePlayerController的本机方法,请再次验证它是否为MPMoviePlayerController方法。@johnykumar谢谢。请参阅我的编辑是否是您的方法pickableRoutesDidChangeNotification如果是,则它将作为NSData方法调用。您的错误显示该方法不是NSData方法。@johnykumar pickableRoutesDidChangeNotification是来自MPMoviePlayerController的本机方法请再次验证它是否为MPMoviePlayerController方法。@johnykumar谢谢请看我的编辑
 -(UIImage *) gerarPreviewVideo:(NSURL *)videoURL {
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
    AVAssetImageGenerator *generateImg = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    NSError *error = NULL;
    CMTime time = CMTimeMake(1, 65);
    CGImageRef refImg = [generateImg copyCGImageAtTime:time actualTime:NULL error:&error];
    UIImage *thumbnail= [[UIImage alloc] initWithCGImage:refImg];
    return thumbnail;
}