MPMoviePlayer - black screen - iOS 5 - no video playing - ios

In iOS 4 this Code worked to play a movie:
-(IBAction)playMovie:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"testbild1" ofType:#"m4v"]];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
UIView *testview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[testview addSubview:moviePlayer.view];
[self.view addSubview:testview];
//[self.view addSubview:moviePlayer.view];
//[moviePlayer setFullscreen:YES animated:YES];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
//[moviePlayerController release];
}
Now, I only get a blackscreen. No controls, nothing. Video path is correct, I tested that. If I add just a white Subview by button click, it works. So the method is called.
Thanks in advance!

I have solved the issue by putting in the .h file
MPMoviePlayerController *moviePlayer;
iOS 5 with ARC works differently than iOS 4.
The .m file must be:
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

If you are on iOS 5.0 or 5.1, check your moviePlyer has a setting like below.
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
If so, when you set [moviePlayer setFullScreen:YES animated:YES];
then MPMoviePlayerPlaybackDidFinishNotification notification will be called instead of being called MPMoviePlayerWillExitFullscreenNotification or MPMoviePlayerDidExitFullscreenNotification

Related

MPMoviePlayerController failed to play video from remote url

If I hit below url in browser, it plays video but my below code is not playing it on iPhone.
http://ec2-107-21-15-206.compute-1.amazonaws.com:8000/static/uploads/1337/photos/5819/38111.mp4
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://ec2-107-21-15-206.compute-1.amazonaws.com:8000/static/uploads/1337/photos/5819/38111.mp4"]];
moviePlayer.controlStyle=MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay=YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
this is the screenshot of the iPhone.
MPMoviePlayerController is deprecated. You can use AVPlayer instead.
AVPlayer *player = [AVPlayer playerWithURL:"URL"];
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
[self presentViewController:controller animated:YES completion:nil];
controller.player = player;
[player play];
You need to tell the MPMoviePlayerController that it needs to stream the video. Just add the following line:
moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
yes , you have to tell its streaming url as :
moviePlayer.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
then prepare to play
[moviePlayer prepareToPlay];

MPMoviePlayerController Won't Play Video

The following MPMoviePlayerController will not present in my iOS application.
I am trying to make it appear when my tableView row is selected:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:videoUrl]];
[player setFullscreen:YES];
[player play];
[self.tableView addSubview:player.view];
}
Any ideas?
Instead try:
MPMoviePlayerViewController *player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:videoUrl]];
[player prepareToPlay];
[self presentViewController:player animated:YES completion:nil];
I wouldn't add the view as a subview of a table view if I were you.
You have forgotten to give player.view a size.
You have forgotten to say prepareToPlay to the player. An MPMoviePlayerController absolutely will not play until you have done that.

MPMoviePlayerController blank on layer

i need to play the MPMoviePlayerController over a layer of UIView. But only sound that came out, no video.
theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[theMovie prepareToPlay];
theMovie.view.frame = CGRectMake(0, 0, 200, 150);
[theMovie setControlStyle:MPMovieControlStyleDefault];
[theMovie setFullscreen:NO animated:YES];
theMovie.shouldAutoplay = YES;
[theMovie setContentURL:movieURL];
[self addSubview:theMovie.view];
[theMovie play];
I only got a black screen, and only audio. Is this because i called the UIView as layer and not as subview? Because my requirement is to call the UIView as layer.
It looks good,try adding this:
[_openingMovie setMovieSourceType:MPMovieSourceTypeStreaming];
Hope this helps
Edit
try setting ContentURL after Setting the SourceType like below,
moviePlayerController_ = [[MPMoviePlayerViewController alloc] init];
moviePlayerController_.movieSourceType = MPMovieSourceTypeStreaming;
[moviePlayerController_.moviePlayer setContentURL:url];
This code snap is from:
An AVPlayerItem cannot be associated with more than one instance of AVPlayer'

How to play video stream with MPMoviePlayerController in iOS

I am trying to play a video stream from the internet on the iPhone by pressing a button.
I used many code samples but nothing worked. With this code it opens a black view without any video stream or controls in it. (The stream itself works.)
NSURL *url = [NSURL URLWithString:#"http://MyStreamURL.com"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
Instead of creating a MPMoviePlayerController and adding that to your view, it is probably simpler to create a MPMoviePlayerViewController and present that view controller modally (since you are trying to show your video full screen anyway). Then the MPMoviePlayerViewController can manage the presentation of your video for you.
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
mpvc.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentMoviePlayerViewControllerAnimated:mpvc];
[mpvc release];
In your moviePlayBackDidFinish delegate method you can then dismiss the model view controller.
Need to mention movie source type as streaming
moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
Add AVFoundation frame work in Link Libraries section
In your .h file add
#import <MediaPlayer/MediaPlayer.h>
#interface video_liveViewController : UIViewController<MPMediaPickerControllerDelegate,MPMediaPlayback>
In your .m file
NSURL *movieURL = [NSURL URLWithString:#"http://172.31.17.252:1935/live/myStream/playlist.m3u8"];
movieController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:movieController];
[movieController.moviePlayer play];
just add "MPMovieSourceTypeStreaming" to "moviesourcetype"

MPMoviePlayerViewController Hide Status Bar

I have an iPad application that creates and shows a video with an MPMoviePlayerViewController. Here's my code:
MPMoviePlayerViewController *mpvc = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:URLEncode(uri)]];
[mpvc setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[mpvc setWantsFullScreenLayout:YES];
[<MainViewController> presentModalViewController:mpvc animated:YES];
Movie load/playback works fine, however, when the Movie Controller appears, it shows the status bar (connection, battery, hour) at the top, even when I have it deactivated on my main window.
I've tried doing:
[mpvc setWantsFullScreenLayout:YES];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
And nothing seems to work, HOWEVER if I also put:
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
The status bar disappears! But the Movie Controller still gets resized as if the status bar is there (even when I already used -setWantsFullScreenLayout:).
Can someone point me to an easy (proven) way to show the video without the status bar?
Thanks.
Just realised the question was iPad-specific. My code was for the iPhone, but some of it may help you anyway.
I had to do this a couple days ago, I think your issue is simply not calling hide on the status bar after the video starts playing. Either way I have the tried and tested code here which works from 3.0 to 4.2:
- (IBAction) playIntroVideo
{
NSString *videoString = [[NSBundle mainBundle] pathForResource:#"intro" ofType:#"mp4"];
NSURL *videoURL = [NSURL fileURLWithPath:videoString];
_player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
if
(
[_player respondsToSelector:#selector(view)] &&
[_player respondsToSelector:#selector(setFullscreen:animated:)] &&
[_player respondsToSelector:#selector(setControlStyle:)]
)
{
[[_player view] setFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT_FULL)];
[_player setFullscreen:YES animated:YES];
[_player setControlStyle:MPMovieControlStyleNone];
[self.view addSubview:[_player view]];
}
[_player play];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(terminateVideo)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[[UIApplication sharedApplication] setStatusBarHidden:YES];
self.navigationController.navigationBarHidden = YES;
}
- (void) terminateVideo
{
[[UIApplication sharedApplication] setStatusBarHidden:NO];
self.navigationController.navigationBarHidden = NO;
if ([_player respondsToSelector:#selector(view)])
{
[[_player view] removeFromSuperview];
}
_player = nil;
[_player release];
}
The answer to this question has an error at the end:
_player = nil;
[_player release];
These should be reversed:
[_player release];
_player = nil;
Messaging nil with release has no effect.
You can set UIStatusBarHidden in your plist, that should solve it :)

Resources