Usted puede reproducir varios vídeos en la pantalla utilizando el marco AVFoundation: AV Foundation Programming Guide
La desventaja es, que no es tan fácil de usar como el MPMoviePlayerController, y shoul crear una subclase UIView cuales contiene las clases AVFoundation. De esta forma puede crear los controles necesarios para ello, controlar la reproducción de video, animar la vista (por ejemplo, animar la transición a pantalla completa).
Aquí es como lo he usado:
// Create an AVURLAsset with an NSURL containing the path to the video
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
// Create an AVPlayerItem using the asset
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:asset];
// Create the AVPlayer using the playeritem
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
// Create an AVPlayerLayer using the player
AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
// Add it to your view's sublayers
[self.layer addSublayer:playerLayer];
// You can play/pause using the AVPlayer object
[player play];
[player pause];
// You can seek to a specified time
[player seekToTime:kCMTimeZero];
// It is also useful to use the AVPlayerItem's notifications and Key-Value
// Observing on the AVPlayer's status and the AVPlayerLayer's readForDisplay property
// (to know when the video is ready to be played, if for example you want to cover the
// black rectangle with an image until the video is ready to be played)
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[player currentItem]];
[player addObserver:self forKeyPath:@"currentItem.status"
options:0
context:nil];
[playerLayer addObserver:self forKeyPath:@"readyForDisplay"
options:0
context:nil];
puede cambiar el tamaño AVPlayerLayer como desee, incluso mientras se reproduce el video.
Si desea utilizar animaciones mientras cambia el tamaño o reposiciona su AVPlayerLayer, debe modificar sus animaciones predeterminadas, de lo contrario verá que el video de la capa del reproductor no cambia de tamaño en sincronización con su rect. (Gracias a @djromero por su answer regarding the AVPlayerLayer animation)
Aquí hay un pequeño ejemplo de cómo alterar su animación predeterminada. La configuración para este ejemplo es que AVPlayerLayer está en una subclase UIView que actúa como contenedor:
// UIView animation to animate the view
[UIView animateWithDuration:0.5 animations:^(){
// CATransaction to alter the AVPlayerLayer's animation
[CATransaction begin];
// Set the CATransaction's duration to the value used for the UIView animation
[CATransaction setValue:[NSNumber numberWithFloat:0.5]
forKey:kCATransactionAnimationDuration];
// Set the CATransaction's timing function to linear (which corresponds to the
// default animation curve for the UIView: UIViewAnimationCurveLinear)
[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionLinear]];
self.frame = CGRectMake(50.0, 50.0, 200.0, 100.0);
playerLayer.frame = CGRectMake(0.0, 0.0, 200.0, 100.0);
[CATransaction commit];
}];
¿Encontró una respuesta a esto? – Pompair
No. Fue forzado a usar un UIWebView con videos incrustados. –