Skip to content

Instantly share code, notes, and snippets.

@icanswiftabit
Created January 15, 2013 11:44
Show Gist options
  • Save icanswiftabit/4538068 to your computer and use it in GitHub Desktop.
Save icanswiftabit/4538068 to your computer and use it in GitHub Desktop.
@implementation NXAssetReaderManager
@synthesize assetReaders = _assetReaders;
+ (id)sharedManager {
static NXAssetReaderManager *sharedMyManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedMyManager = [[self alloc] init];
});
return sharedMyManager;
}
- (id)init
{
self = [super init];
if (self) {
_assetReaders = [NSMutableArray array];
}
return self;
}
-(void)startProduceAssetReaders:(NSURL*)url {
_producer_queue = dispatch_queue_create("producer_queue", 0);
NSLog(@"Liczba Assetów u producenta %i",[_assetReaders count]);
dispatch_async( _producer_queue, ^{
AVURLAsset * asset = [AVURLAsset URLAssetWithURL:url options:nil];
[asset loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"tracks"] completionHandler:
^{
dispatch_async(_producer_queue, ^{
// while ([_assetReaders count] < 2) {
while (true) {
NSLog(@"Liczba Assetów u producenta %i",[_assetReaders count]);
AVAssetTrack * videoTrack = nil;
NSArray * tracks = [asset tracksWithMediaType:AVMediaTypeVideo];
if ([tracks count] == 1)
{
videoTrack = [tracks objectAtIndex:0];
NSError * error = nil;
AVAssetReader *ar = [[AVAssetReader alloc] initWithAsset:asset error:&error];
// _movieReader is a member variable
NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
AVAssetReaderOutput *output =[AVAssetReaderTrackOutput assetReaderTrackOutputWithTrack:videoTrack outputSettings:videoSettings];
[ar addOutput:output];
[_assetReaders addObject:ar];
// dispatch_async( dispatch_get_main_queue(), ^{
//
// });
NSLog(@"Dodano nowego AssetReadera");
}
}
});
}];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment