8

次のViewController.mで新しいプロジェクトを作成しました。アプリを実行すると、予想される原点/サイズ (38、100、250、163) のボックスが表示されますが、黒く、ビデオが再生されません。Xcode に奇妙な出力があります。

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)

ビデオは Videora iPhone Converter で変換され、Xcode で正常に再生されることに注意してください (したがって、ビデオの問題ではありません)。demo-iPhone1 (存在しない) を指定すると nil 例外が発生するため、ビデオへのパスは問題ありません。私はシミュレーターと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
4

4 に答える 4

13

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

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

環境に合わせて変更してください。

于 2012-10-01T21:55:58.777 に答える
3

追加することで同様の問題を解決しますplayercontroller.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

于 2012-09-07T08:07:07.540 に答える
2

ARCを使用していますか?その場合、MPMoviePlayerController を保持する必要があります。

これをあなたのインターフェースに追加してください

@property (nonatomic, strong) MPMoviePlayerController *controller;

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];
}
于 2012-09-26T09:34:46.827 に答える
-2

ビデオフォーマットもチェックしてください。サンプルビデオ.m4v(AppleのWebサイトからダウンロードしたもの)でこのエラーが発生し続けました。最終的に私はそれがあった別のビデオクリップでそれを試しました、.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

ただし、ビデオは引き続き再生されました。

于 2013-01-22T20:50:22.853 に答える