贝娄我有一些下载视频的代码。该代码以我提供的字符串形式下载视频,每个呼叫只能下载一个视频。我的问题是我是否可以创建一个排队系统,使其可以同时直接开始下一个提供的字符串。
提前致谢

 -(IBAction)download{



    LBYouTubeExtractor *extractor = [[LBYouTubeExtractor alloc] initWithURL:[NSURL URLWithString:URL.text] quality:LBYouTubeVideoQualityLarge];

    [extractor extractVideoURLWithCompletionBlock:^(NSURL *videoURL, NSError *error) {
        if(!error) {

            NSLog(@"Did extract video URL using completion block: %@", videoURL);
            NSURL *url = videoURL;


            [extractor extractVideoURLWithCompletionBlock:^(NSURL *videoURL, NSError *error) {


                if(!error) {




                    NSLog(@"Did extract video URL using completion block: %@", videoURL);


                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

                                            filePath = [NSString stringWithFormat:@"%@/Documents/%@.mp4", NSHomeDirectory(),title.text];
                        filename = [NSString stringWithFormat:(@"video_%@.mp4"), videoURL];
                        data = [NSData dataWithContentsOfURL: videoURL];
                        [data writeToFile:filePath atomically:YES];
                        NSLog(@"File %@ successfully saved", filePath);


                    }

                                   );


                }
                else {
                    NSLog(@"Failed extracting video URL using block due to error:%@", error);
                }
            }];

        } else {
            NSLog(@"Failed extracting video URL using block due to error:%@", error);
        }

    }];

}

最佳答案

看看NSOperationQueue

创建maxConcurrentOperationCount为1的NSOperationQueue并传递您的代码队列块以使用addOperationWithBlock执行相当不容易。就您而言,您可以遍历视频列表,并将每次下载排队到NSOperationQueue中。

关于ios - 如何制作排队系统?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20574083/

10-11 11:29