2012-08-23 15 views
8

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 
+0

Hai provato con qualsiasi altro video. Forse un mp4 scaricato da Vimeo? –

+0

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

risposta

3

ho risolvere un problema simile con l'aggiunta di playercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

+0

+1: questo mi ha aiutato .... grazie a una tonnellata ... –

2

Usi ARC? Se è così, devi mantenere MPMoviePlayerController!

aggiungere questo alla vostra interfaccia

@property (nonatomic, strong) MPMoviePlayerController *controller; 

Controllare ultima linea di viewDidLoad

- (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]; 
    [self setController:moviePlayerController]; 
} 
+0

+1 per il mantenimento. Troppe esercitazioni mostrano l'utilizzo di variabili temporanee. – DanneManne

13

ho appena risolto un problema simile con questa riga di codice. I controller del player ora appaiono e il video viene riprodotto perfettamente:

@property (nonatomic, strong) MPMoviePlayerController *moviePlayer; 
// 
@synthesize moviePlayer = _moviePlayer; 
// 
[self.moviePlayer prepareToPlay]; 

Modifica per adattarsi al proprio ambiente.

+2

La chiamata "prepareToPlay" su iPad/iOS6 ha risolto questo problema per me. Senza di esso, "MPMoviePlayerLoadStateDidChangeNotification" non è stato inviato perché il giocatore non si è preoccupato di precaricare il video. – diachedelic

+1

Risolto il problema anche per me, prima che avessi schermi neri su iOS6 (mentre funzionava bene su iOS5 e versioni precedenti). – Dado

+0

questo ha risolto anche il mio problema, tuttavia, caricando un altro video da uno splitView in 5 secondi, riesco ancora a sentire l'audio dal video precedente fino a che non sono trascorsi 5 secondi ... qualcuno ha questo problema? Sto pensando di aggiungere il framework AVFoundation solo così posso provare a controllare le sessioni audio? – whyoz

-2

Controllare anche il formato video. Ho continuato a ricevere questo errore con il mio video campione .m4v (che ho scaricato dal sito Web di Apple). Alla fine ho provato con un altro video clip che era .mp4 e ha funzionato bene. Molti degli errori sono ancora spuntati sulla mia console.

2013-01-22 15:44:04.850 VideoTesting[4497:c07] [MPAVController] Autoplay: Likely to keep up or full buffer: 0 
2013-01-22 15:44:04.851 VideoTesting[4497:c07] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up. 
2013-01-22 15:44:04.853 VideoTesting[4497:c07] [MPAVController] Autoplay: Disabling autoplay for pause 
2013-01-22 15:44:04.853 VideoTesting[4497:c07] [MPAVController] Autoplay: Disabling autoplay 
2013-01-22 15:44:04.861 VideoTesting[4497:c07] [MPAVController] Autoplay: Enabling autoplay 

Il video è comunque riprodotto.

Problemi correlati