Pergunta

Provavelmente estou perdendo algo realmente óbvio.

Eu incluí <MediaPlayer/MediaPlayer.h> E tenha este código:

NSURL *videoURL = [NSURL fileURLWithPath:pathToFile];
MPMoviePlayerViewController *mediaPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
[self presentMoviePlayerViewControllerAnimated:mediaPlayer];
mediaPlayer.view.backgroundColor = [UIColor blackColor];
[mediaPlayer release];

Mas o vídeo não será reproduzido. Copiei o código de outro lugar onde o vídeo funciona perfeitamente.

pathToFile está correto porque a variável é usada em linhas anteriores para mover o vídeo da pasta de recursos para o diretório de documentos.

Alguma idéia de por que isso pode não estar funcionando?

Obrigado

Foi útil?

Solução

Você pode usar o seguinte código, exceto no PresentMoviePlayerviewControlleRenimated

NSString *movieFile=[[NSBundle mainBundle] pathForResource:@"movie" ofType:@"m4v"];
moviePlayer= [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.view.frame = self.view.frame;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];

Este trabalho é bom para mim.

Outras dicas

Eu não acho presentMoviePlayerViewControllerAnimated Mantém o receptor, então parece que você está lançando seu jogador de cinema muito cedo. Você pode tentar fazer do MediaPlayer uma propriedade retida:

@interface MyClass : SuperClass {
    MVMoviePlayerViewController *mediaPlayer;
}
@property (nonatomic, retain) MVMoviePlayerViewController *mediaPlayer;
@end

@implementation MyClass 
@synthesize mediaPlayer;
// rest of class implementation here...
@end

Então inicialize como assim:

self.mediaPlayer = [[[MPMoviePlayerViewController alloc] 
                    initWithContentURL:videoURL] autorelease];

E lançar depois com:

self.mediaPlayer = nil;

(Para escrever código que acontece após o término do vídeo, confira o MPMoviePlayerPlaybackDidFinishNotification notificação.)

Também tenha em mente que presentMoviePlayerViewControllerAnimated Apareceu pela primeira vez no iOS 3.2, para que esse código não funcione nas versões anteriores do iOS. Mas não acho que esse seja o problema neste caso.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top