2012-08-23 12 views
8

次のViewController.mで新規プロジェクトを作成しました。私はアプリを実行すると、予想される起点/サイズ(38,100,250,163)のボックスを見ることができますが、それは黒であり、ビデオは再生されません。 Xcodeで奇妙な出力があります:ビデオは(それがビデオの問題ではありません)ビデオラiPhoneのコンバーターで変換し、Xcodeで[OK]を果たしていることを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) 

注; demo-iPhone1(これは存在しない)を指定すると、nil例外が発生するため、ビデオへのパスはokです。私はSimulatorとiPhoneで試しました。常にブラックボックスです。何か案は?

#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

他のビデオで試しましたか? mp4がvimeoからダウンロードされたのでしょうか? –

+0

Steve、ビデオはまったく同じコードの私の別のアプリで再生されるので、本当に大丈夫です。しかし、まだ違いを理解することはできません。私はXcodeの出力を追加しました。たぶんそれはあなたに何が問題なのかを知らせるでしょう。 – maxgrinev

答えて

3

私はplayercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

+0

+1:これは私を助けました....ありがとうトン... –

2

あなたはARCを使用していますを追加することにより、同様の問題を解決しますか?もしそうなら、あなたはMPMoviePlayerControllerを保持しなければなりません!

あなたのインターフェイスにの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のために保持する。チュートリアルが多すぎると、一時変数の使用が示されます。 – DanneManne

13

@property (nonatomic, strong) MPMoviePlayerController *controller; 

チェック最後の行を、これを追加私はこのコード行で同様の問題を解決しました。プレーヤーコントローラが表示され、ビデオが完全に再生されます。

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

ご使用の環境に合わせて変更してください。

+2

iPad/iOS6で "prepareToPlay"を呼び出すと、これが修正されました。それがなければ、プレーヤーはビデオをプリロードする必要がないので、「MPMoviePlayerLoadStateDidChangeNotification」は送信されませんでした。 – diachedelic

+1

iOS6で黒い画面が表示される前に、iOS5以降で正常に動作していた間に、この問題も修正されました。 – Dado

+0

しかし、5秒以内にSplitViewから別のビデオを読み込んでいるときに、私はまだ5秒が経過するまで前のビデオの音声を聞くことができます。誰でもこの問題がありますか?私はAVFoundationフレームワークのaddindについて考えているので、オーディオセッションを試して制御することはできますか? – whyoz

-2

ビデオ形式もチェックしてください。サンプルビデオ.m4v(Appleのウェブサイトからダウンロードしたもの)でこのエラーが発生しました。最終的に私は.mp4だった別のビデオクリップで試してみました。エラーの多くはまだ私のコンソールにポップアップしました。

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 

ビデオはまだ再生されました。

関連する問題