I want to stream video on my iOS application, the problem is that it displays a black screen with the url I want to show but it works with other url's here is my code :
[super viewDidLoad];
NSURL *fileURL = [NSURL URLWithString:#"http://livevideo.infomaniak.com/iframe.php?stream=arabelfmendirect&name=arabel_webtv&player=2828.m3u8"];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)];
[self.view addSubview:moviePlayerController.view];
// moviePlayerController.fullscreen = YES;
[moviePlayerController prepareToPlay];
[moviePlayerController play];
how can I fix it ?
The video URL mentioned doesn't use HLS format. Thus MPMoviePlayerController cannot play the video.
From http://livevideo.infomaniak.com/iframe.php?stream=arabelfmendirect&name=arabel_webtv&player=2828.m3u8, it looks like it needs flash to play the video.
Related
I am trying to play a video from url and the only thing i am getting is a black screen and a loading wheel?
I have a XML/JSON from witch i need somehow to play the video,
I tried with all 3 links i have there and no response
NSURL *url = [[NSURL alloc] initWithString:#"http://rutube.ru/play/embed/7224398"];
moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
[moviePlayer.view setFrame:CGRectMake(self.view.frame.origin.x , self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES];
[moviePlayer setShouldAutoplay:YES];
Is there a chanse to start this video using MPMoviePlayerController ??
P.S: I managed to load the video in a WebView but its not what i need.
You have to extract direct link to .mp4 file somehow.
Check this article.
I am trying to add an intro video into my iOS app. I want the video to play with no controls and in a box I create for it. but am not sure how to do that. It is also not playing at the correct size it is super small. If you look below you will see my attempt but it fails to work. How do I achieve this?
-(void)initVideo{
MPMoviePlayerViewController *moviePlayerController=[[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"video" ofType:#"mp4"]]];
UIView * contain = [[UIView alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
[contain addSubview:moviePlayerController.view];
[self.view addSubview:contain];
MPMoviePlayerController *player = [moviePlayerController moviePlayer];
player.fullscreen = NO;
[player play];
}
I actually have code in my book that shows you exactly how to do this very thing:
http://www.apeth.com/iOSBook/ch28.html#_mpmovieplayercontroller
Read down to the first block of code. As you can see, we load a movie, decide on the rect within our view where we want to display it, and display it:
NSURL* m = [[NSBundle mainBundle] URLForResource:#"ElMirage"
withExtension:#"mp4"];
MPMoviePlayerController* mp =
[[MPMoviePlayerController alloc] initWithContentURL:m];
self.mpc = mp; // retain policy
self.mpc.shouldAutoplay = NO;
[self.mpc prepareToPlay];
self.mpc.view.frame = CGRectMake(10, 10, 300, 250);
self.mpc.backgroundView.backgroundColor = [UIColor redColor];
[self.view addSubview:self.mpc.view];
Of course you will want to change those values! But that's the technique. Also you're going to want to get rid of the controls, but that's easy (read further down in the chapter).
Since you are using the player in a view, you don't need to use a MPMoviePlayerViewController. Try the following code:
-(void)initVideo{
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"video" ofType:#"mp4"]]];
UIView *contain = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
moviePlayerController.view.frame = contain.bounds;
[contain addSubview:moviePlayerController.view];
[self.view addSubview:contain];
moviePlayerController.fullscreen = NO;
[moviePlayerController play];
}
Also, if you are using a navigation bar or status bar, you should take that away from the height:
CGRect f = [[UIScreen mainScreen] bounds];
f.size.height -= [[UIApplication sharedApplication] statusBarFrame].size.height + self.navigationController.navigationBar.frame.size.height;
UIView *contain = [[UIView alloc] initWithFrame:f];
I'm trying to use an MPMoviePlayerController on iOS to play back an audio stream over HTTP.
I've imported MediaPlayer.framework and used the code from MPMoviePlayerController's documentation, but I get no sound.
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:#"http://shoutmedia.abc.net.au:10326"]];
[player prepareToPlay];
[player.view setFrame: self.view.bounds]; // player's frame must match parent's
[self.view addSubview: player.view];
[player play];
I've also tried adding player.movieSourceType = MPMovieSourceTypeStreaming; but didn't work neither.
Any thoughts?
I am currently trying to play a youtube video in iPad but device only display blank screen.
- (void)viewDidLoad {
[super viewDidLoad];
NSURL* videoURL = [NSURL URLWithString:#"http://www.youtube.com/......."];
MPMoviePlayerController * moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
[moviePlayer prepareToPlay];
[moviePlayer play];
[moviePlayer.view setFrame:CGRectMake(50, 200, (self.view.frame.size.width)-100 , 400)];
moviePlayer.view.backgroundColor = [UIColor grayColor];
[self.view addSubview:moviePlayer.view];
}
This will just display a blank gray screen,But if i try to play any locally stored video file then i can able to play by MPMoviePlayerController.So what is the best way to play a youtube video in iPad.
I am using the MPMoviePlayerController to play a movie from the web.
Depending on the table row selected a different movie is loaded. However, i would like the MPMoviePlayerController to disappear (or hide itself), once a new row is selected.
Here is the code that gets called to play my movie and to, eventually, hide it
- (IBAction) playMovie{
NSURL *url = [NSURL URLWithString:vidMovie];
moviePlayer = [[MPMoviePlayerController alloc]initWithContentURL:url];
moviePlayer.view.frame = vidPlayer.frame;// CGRectMake(64, 624, 640, 360);
[self.view addSubview:moviePlayer.view];
[moviePlayer play];
}
- (void) hidePlayer{
[moviePlayer stop];
[moviePlayer release];
}
in my .h i declare moviePlayer as such
MPMoviePlayerController *moviePlayer;
I've tried setting the moviePlayer frame height and width to 0 but that still shows the play button.
I've tried the variables .hidden and .opaque and still i get nothing
Could anyone help me figure out what i might have forgotten. Any help would be greatly appreciated!
Thanks
I found it after trying all sorts of different things...
Seems i needed to retain my moviePlyer to be able to remove it in another part of my code.
If anyone has the same problem, here is my solution!
- (IBAction) playMovie{
NSURL *url = [NSURL URLWithString:vidMovie];
moviePlayer = [[[MPMoviePlayerController alloc]initWithContentURL:url] retain];
moviePlayer.view.frame = vidPlayer.frame;// CGRectMake(64, 624, 640, 360);
[self.view addSubview:moviePlayer.view];
[moviePlayer play];
}
- (void) hidePlayer{
[moviePlayer stop];
[moviePlayer.view removeFromSuperview];
}
Hope this might be able to help othes!