Reproducción de video en pantalla de tamaño personalizado - ver en iPhone
-
07-07-2019 - |
Pregunta
Suponga que el usuario toca un botón y el video comienza a reproducirse. Ahora, cuando se reproduce el video, siempre está en modo de pantalla completa.
El video debe reproducirse en modo vertical (pero normalmente el video se reproduce en modo horizontal). ¿Cómo puedo hacer esto?
Solución
@interface MPMoviePlayerController (extend)
-(void)setOrientation:(int)orientation animated:(BOOL)value;
@end
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieUR];
[moviePlayer setOrientation:UIDeviceOrientationPortrait animated:NO];
if (moviePlayer)
{
[self.moviePlayer play];
}
Apple rechazará esta solución, ya que setOrientation para reproductor de películas es la API privada. Debe tener cuidado, pero puede funcionar en iPhones Jailbroke.
Otros consejos
Solo una actualización, el último iPhone SDK 3.2+ ahora permitirá a los programadores mostrar el video en cualquier tamaño y orientación deseados, se proporciona el nuevo MPMoviePlayerView, que es una propiedad de MPMoviePlayerController, esta vista tendrá el video, que usted tendrá puede agregarse como una subvista a su vista.
De los documentos documentados, no creo que esto sea posible utilizando el reproductor multimedia incorporado
Prueba esto. Encontré algo nuevo.
@interface MPMoviePlayerController (extend)
-(void)setOrientation:(int)orientation animated:(BOOL)value;
@end
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieUR];
[moviePlayer setOrientation:UIDeviceOrientationPortrait animated:NO];
if (moviePlayer)
{
[self.moviePlayer play];
}
Esto es lo que hice. Agregue NSNotification para notificarle cuando finalice la precarga del video.
- (void)playVideoUrl:(NSString *)videoUrl {
NSURL *url = [NSURL URLWithString:videoUrl];
MPMoviePlayerController* theMovie=[[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
//MPMoviePlayerContentPreloadDidFinishNotification
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedPreloading:)
name:MPMoviePlayerContentPreloadDidFinishNotification
object:theMovie];
// Movie playback is asynchronous, so this method returns immediately.
[theMovie play];
}
Selector de devolución de llamada:
-(void)myMovieFinishedPreloading:(NSNotification*)aNotification {
NSArray *windows = [[UIApplication sharedApplication] windows];
UIWindow *moviePlayerWindow = nil;
if ([windows count] > 1)
{
moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
}
CGAffineTransform transform = CGAffineTransformMakeScale(0.5, 0.5);
transform = CGAffineTransformRotate(transform, -90.0f*M_PI/180.0f);
[moviePlayerWindow setTransform:transform];
}