1

私はこれまでiOSでビデオファイルを再生したことがないので、何かが足りないのかどうかわかりません。プレーヤーは開きますが、読み込み中のアニメーションで動かなくなり、[完了]ボタンを押すことができません。私のビデオファイルがサポートされていない可能性がありますか?iPad用にエンコードしました。

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    UIButton *video_btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    video_btn.frame = CGRectMake(0, 0, 100, 50);
    [video_btn setTitle:@"Moonrise" forState:UIControlStateNormal];
    [video_btn addTarget:self action:@selector(playMovie:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:video_btn];



}

-(IBAction)playMovie:(id)sender
{

    NSString *filepath   =   [[NSBundle mainBundle] pathForResource:@"moonrise" ofType:@"mp4"];
    NSURL    *fileURL    =   [NSURL fileURLWithPath:filepath];
    MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
    [self.view addSubview:moviePlayerController.view];
    moviePlayerController.fullscreen = YES;
    [moviePlayerController play];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

私はこれを出力として取得します:

2012-09-25 12:47:56.206 App[4895:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-09-25 12:47:56.207 App[4895:c07] [MPAVController] Autoplay: Disabling autoplay
2012-09-25 12:47:56.221 App[4895:c07] [MPAVController] Autoplay: Disabling autoplay for pause
2012-09-25 12:47:56.222 App[4895:c07] [MPAVController] Autoplay: Disabling autoplay
2012-09-25 12:47:56.226 App[4895:c07] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-09-25 12:47:56.255 App[4895:c07] [MPAVController] Autoplay: Enabling autoplay
4

1 に答える 1

0

MPMoviePlayerControllerをプロパティとして設定してみてください。

@property (strong, nonatomic) MPMoviePlayerController *moviePlayerController;

自動的に閉じるには、MPMoviePlayerControllerで通知を設定する必要があります。このような:

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(videoFinishedCallback:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:moviePlayerController];

これにより、ビデオが終了したときに関数--videoFinishedCallbackが呼び出されます。次に、コールバックを実装します。

- (void) videoFinishedCallback:(NSNotification*)aNotification
{
    //remove notification
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:object:moviePlayerController];

    // here you set your code to remove the video
    // for example, you can remove from superview and set value to nil
}
于 2012-09-25T17:40:57.363 に答える