Reproduzindo vídeo na tela de tamanho personalizado - Veja no iPhone
-
07-07-2019 - |
Pergunta
Suponha que as torneiras de usuário em um botão e o vídeo comece a reproduzir. Agora, quando o vídeo é reproduzido, ele sempre no modo de tela inteira.
O vídeo deve ser reproduzido no modo retrato (mas normalmente o vídeo é reproduzido no modo paisagem). Como posso fazer isso?
Solução
@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];
}
Esta solução será rejeitada pela Apple, pois a Setorientation for Movie Player é a API privada. Você precisa ter cuidado, mas pode funcionar nos iPhones do Jailbroke.
Outras dicas
Apenas uma atualização, o mais recente iPhone SDK 3.2+ agora permitirá que os programadores mostrem o vídeo em qualquer tamanho e orientação desejados, é fornecido um novo MPMoviePlayerView, que é uma propriedade do MPMoviePlayerController, essa visualização terá o vídeo, que você pode adicionar como como uma subview para sua visão.
Dos documentos documentados, não acho que isso seja possível usando o mídia embutido
Experimente isso. Eu encontrei algo novo.
@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];
}
Aqui está o que eu fiz. Adicione a NSNotificação para notificá -lo quando a pré -carga do vídeo terminar.
- (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];
}
Seletor de retorno de chamada:
-(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];
}