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!
Related
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.
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 use MPMoviePlayerController for displaying a video. The problem is that I don't want to display the video in full screen, I just want to display it in a small view.
In full screen is working but when I add this line (to set the video frame) it doesn't work anymore.
_moviePlayer.view.frame = CGRectMake(250, 150, 500, 500);
Here is my code:
ViewController.h
#property (strong, nonatomic) MPMoviePlayerController *moviePlayer;
ViewController.m
NSURL *url = [NSURL URLWithString:
#"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
_moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:_moviePlayer];
_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[_moviePlayer setScalingMode:MPMovieScalingModeFill];
_moviePlayer.view.frame = CGRectMake(250, 150, 500, 500);
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:NO animated:YES];
Any ideas? or maybe MPMoviePlayerController is not the right object?
Thanks!
skipp the line [_moviePlayer setScalingMode:MPMovieScalingMofeFill] . this line does not allow to you to show your video within the RECTMAKE because this has to fill complete screen .
I'm trying to create an app where I have a video playing within a MPMoviePlayerController. If the video gets paused, it takes a screenshot with thumbnailImageAtTime. The problem is that the image MPMoviePlayerController displays after pause and the screenshot I get with thumbnailImageAtTime aren't the same.
My code looks like this:
[self.moviePlayer pause]
[self.moviePlayer thumbnailImageAtTime:self.moviePlayer.currentPlaybackTime timeOption:MPMovieTimeOptionExact];
Screenshot
Any help is highly appreciated :)
What I used is MPMovieTimeOptionNearestKeyFrame
- (UIImage *)imageFromMovie:(NSURL *)movieURL atTime:(NSTimeInterval)time {
// set up the movie player
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc]
initWithContentURL:movieURL];
mp.shouldAutoplay = NO;
mp.initialPlaybackTime = time;
mp.currentPlaybackTime = time;
// get the thumbnail
UIImage *thumbnail = [mp thumbnailImageAtTime:time
timeOption:MPMovieTimeOptionNearestKeyFrame];
// clean up the movie player
[mp stop];
[mp release];
return(thumbnail);
}
Try this
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.