iOS无法播放视频

时间:2014-10-07 15:43:35

标签: ios

我正在尝试在视图加载时全屏播放一个简单的mp4文件。这是代码:

我根本没有收到视频,但我知道正在调用viewDidLoad并且存在一个视图。

//
//  FirstViewController.m
//  WSTR Finale
//
//  Created by Chris Muench on 10/6/14.
//  Copyright (c) 2014 World Series of Team Roping. All rights reserved.
//

#import "WatchLiveViewController.h"
#import <MediaPlayer/MediaPlayer.h>

@interface WatchLiveViewController ()

@end

@implementation WatchLiveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSURL *movieURL = [NSURL URLWithString:@"http://download.wavetlan.com/SVV/Media/HTTP/H264/Talkinghead_Media/H264_test1_Talkinghead_mp4_480x360.mp4"];
    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
    moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
    moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
    UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
    [moviePlayer.view setFrame:backgroundWindow.frame];
    [backgroundWindow addSubview:moviePlayer.view];
    [moviePlayer play];
}

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

@end

2 个答案:

答案 0 :(得分:1)

试试这段代码:

MPMoviePlayerViewController *mpvController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
mpvController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
mpvController.moviePlayer.scalingMode = MPMovieScalingModeFill;
mpvController.view.transform = CGAffineTransformConcat(mpvController.view.transform, CGAffineTransformMakeRotation(M_PI_2));
[self presentViewController:mpvController animated:NO completion:^{
    [mpvController.moviePlayer play];
}];

答案 1 :(得分:0)

我认为你遗失了prepareToPlay。尝试这样的事情:

...
[moviePlayer prepareToPlay];
[moviePlayer play];