Reputation: 3483
I just want to load a video file which is in the main bundle, this seems pretty simple but for some reason I keep getting an error of the MPMoviePlayerController
, I have the following code.
- (void)viewDidLoad{
[super viewDidLoad];
NSString *path = [[NSBundle mainBundle] pathForResource:@"ipad2" ofType:@"mp4"];
self.myPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:path]];
[self.myPlayer prepareToPlay];
self.myPlayer.movieSourceType = MPMovieSourceTypeFile;
[self.myPlayer.view setFrame:self.view.bounds];
[self.view addSubview:self.myPlayer.view];
[self.myPlayer play];
}
I only get a black screen and the following output:
2013-01-09 13:38:15.686 myVideoApp[1789:907] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
2013-01-09 13:38:15.690 myVideoApp[1789:907] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
I also tried adding these notification for playing but is never sent:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(playVideo:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:self.myPlayer ];
And when I print self.myPlayer.loadState
I get 0
which is undefined loadState.
These is a simple viewController with any other method, and I have these declaration on the .h
file:
@property (nonatomic, strong) MPMoviePlayerController *myPlayer;
I`m running on iOS 6, and these happens both in device and simulator
Upvotes: 1
Views: 787
Reputation: 376
I also using the MPMoviePlayerViewController to live video on my app and getting same above list errors.And I found MPMoviePlayer not support larger data to show video but if you used smaller data of video is working fine its not give any error. In fact is not problem of prepare to play and play property of movie player.
If you need to show larger data then used webview on your app.
Upvotes: 0
Reputation: 27984
NSString *path = [[NSBundle mainBundle] pathForResource:@"ipad2" ofType:@"mp4"];
Have you checked in the debugger that path
is not nil
?
self.myPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:path]];
That's the wrong way to create a URL from a file path. Use +[NSURL fileURLWithPath:]
instead.
Upvotes: 2