Dispense mpmovieplayerviewController no erro de reprodução
-
26-09-2019 - |
Pergunta
Tenho um problema com o MPMovieplayerviewController: se o controlador não conseguir encontrar o filme no URL especificado, ele exibe uma tela branca e não consigo chegar perto.
É assim que eu começo o jogador do cinema:
- (void) playVideo:(NSString*)path
{
NSURL* url = [NSURL URLWithString:path];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
double osversion = [[[UIDevice currentDevice] systemVersion] doubleValue];
if (osversion >= 3.2)
{
mplayerVC = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
if (mplayerVC)
{
mplayerVC.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[mplayerVC.moviePlayer play];
mplayerVC.moviePlayer.shouldAutoplay = TRUE;
[self presentMoviePlayerViewControllerAnimated:mplayerVC];
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerLoadStateChanged:) name:MPMoviePlayerLoadStateDidChangeNotification object:nil];
}
}
}
E é assim que MoviePlaybackDidfinish: Método se parece com este
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
NSError* error = [[notification userInfo] valueForKey:@"error"];
if (error != nil)
{
// Movie ended with an error
DLog(@"error=%@", error);
}
else
{
// Movie ended successfully
}
[self dismissMoviePlayerViewControllerAnimated];
SAFE_DEL(mplayerVC);
}
A tela branca só acontece se o URL estiver apontando errado
Solução
Não importa pessoal, eu descobri.
Aparentemente, no método MoviePlaybackDidfinish, você deve ligar
[player stop];
antes de descartar o controlador.
Acima, o jogador é o objeto MPMoviePlayerController obtido assim:
MPMoviePlayerController *player = [notification object];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow