I utworzeniu niestandardowego aparat podobny do snapchat z AVFoundation. Aspekt obrazu działa: zrób zdjęcie i wyświetl obraz. Teraz próbuję zrobić wideo i wyświetlić wideo.Odtwarzanie wideo z AVPlayer po AVCaptureMovieFileOutput
mam zrobione udanej plik wideo, przetestowane i współpracuje z MPMoviePlayer, ale jestem w stanie go odtworzyć na AVPlayer.
- (void)takeVideoAction:(id)sender {
NSString *outputPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"output.mp4"];
NSFileManager *manager = [[NSFileManager alloc] init];
if ([manager fileExistsAtPath:outputPath]){
[manager removeItemAtPath:outputPath error:nil];
}
[movieFileOutput startRecordingToOutputFileURL:[NSURL fileURLWithPath:outputPath] recordingDelegate:self];
}
- (void)captureOutput:(AVCaptureFileOutput *)captureOutput didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL fromConnections:(NSArray *)connections error:(NSError *)error{
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:outputFileURL options:nil];
[asset loadValuesAsynchronouslyForKeys:@[@"tracks"] completionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
NSError *error = nil;
if([asset statusOfValueForKey:@"tracks" error:&error] == AVKeyValueStatusFailed){
NSLog(@"error: %@", [error description]);
}
else{
self.playerItem = [AVPlayerItem playerItemWithAsset:asset];
self.player = [AVPlayer playerWithPlayerItem:self.playerItem];
self.playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player];
self.playerLayer.frame = self.view.bounds;
[self.view.layer addSublayer:self.playerLayer];
[self.player play];
}
});
}];
}
To jest mój pierwszy raz przy użyciu AVFoundation & AVPlayer. Czy po ładowaniu zasobu nie mogę [self.player play]
? Muszę czekać na stan elementu do AVPlayerItemStatusReadyToPlay
?
ERROR "Żądany URL nie został odnaleziony na tym serwerze" Błąd Domain = kod NSURLErrorDomain = -1100