thumbnailImageAtTime not exact - ios

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

Related

Best way to play video from Url in iOS

I am playing a video from Url, It is playing but very slow. I am using my mobile data.
Her is the code I play the video:
self.avPlayer = [AVPlayer playerWithURL:[NSURL URLWithString:_selectedVideo.videoLink]];
self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
videoLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
videoLayer.frame = self.view.bounds;
[self.view.layer addSublayer:videoLayer];
[self.avPlayer play];
It is really slow and takes long time to start. Is there any way to make it faster?
Thanks
You can try mpmovieplayer to play video.
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds]; // player's frame
[myView addSubview: player.view];
// ...
[player play];

movieplayercontroller doesn't work

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.

RuTube MPMoviePlayerController initWithContentURL:

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.

Failed to play a youtube video in iPad

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.

Remove MPMoviePlayerController

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!

Resources