Ho creato un nuovo progetto con il seguente ViewController.m. Quando eseguo l'app, posso vedere una scatola dell'origine/dimensione prevista (38, 100, 250, 163) ma è nera e non riproduce video. C'è una strana uscita in Xcode:Impossibile riprodurre video con MPMoviePlayerViewController
2012-08-23 15:36:45.559 VideoTest1[11398:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-08-23 15:36:45.560 VideoTest1[11398:c07] [MPAVController] Autoplay: Disabling autoplay
2012-08-23 15:37:18.186 VideoTest1[11398:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
Nota che il video è convertito con Videora iPhone Converter e gioca ok in Xcode (quindi non è un problema video); il percorso per il video è ok perché quando si specifica demo-iPhone1 (che non esiste) ottengo un'eccezione nulla. Ho provato in simulatore e su iPhone: sempre scatola nera. Qualche idea?
#import "ViewController.h"
#import <MediaPlayer/MediaPlayer.h>
@interface ViewController()
@end
@implementation ViewController
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"demo-iPhone" ofType:@"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view setFrame:CGRectMake(38,
100,
250,
163)];
[self.view addSubview:moviePlayerController.view];
[moviePlayerController play];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
Hai provato con qualsiasi altro video. Forse un mp4 scaricato da Vimeo? –
Steve, il video è davvero ok perché suona nella mia altra app con esattamente lo stesso codice. Ma ancora non riesco a capire la differenza. BTW ho aggiunto l'output Xcode. Forse ti darà un'idea di quale sia il problema. – maxgrinev