Playing .mov .mp4 in diffent resolution size in iPhone - iphone

I have to develop a player in iPhone that play videos. I have not much background in video encoding and signal encoding. When I test some .mp4 and .mov file I see that only the video with resolution that fits the iPhone screen size can be played and larger size cannot be played. Are there any solutions to play all the movie size on iPhone in that case. Please give me some instruction. Many thanks in advance. The code to play the video is below:
NSURL *url = [NSURL URLWithString:#"http://192.65.123.108/test1.mov"];
//this movie has size of 480x272 can be played, other larger resolution cannot be played
_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];

I don't think there is a way to do this, unless you can scale the video down before you play it. It would probably be inefficient though.

Related

MP4 file not playing in MPMoviePlayerController?

I am using MPMoviePlayerController to play .mp4 file, while I'm testing .mp4 recorded in windows platform its working fine, however .mp4 recorded using Android is not playing in my iOS device(iPod touch), Player keeps on buffering it.. Any Idea what could be the problem? And please help me, how to debug the issue in MPMoviePlayerController.
NSURL *file_url = [NSURL fileURLWithPath:filepath];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL:file_url];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
// moviePlayer.useApplicationAudioSession = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
thanks
I have found the problem, iOS not supporting the audio format, which is recorded in Android. Now I recorded using AAC it is playing fine.

more than one MPMoviePlayer in a view?

I need to display more than one movieplayer in a view.
I know I can only play one video.
My problem is that only one of the two MPMovieplayer, I have added to the view, shows me the control buttons.
What can I do to solve my problem?
I use this code to add a movieplayer:
MPMoviePlayerController * moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playerPlaybackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playerDidEnterFullscreen:)
name:MPMoviePlayerDidEnterFullscreenNotification
object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playerDidExitFullscreen:)
name:MPMoviePlayerDidExitFullscreenNotification
object:moviePlayer];
moviePlayer.view.frame = rect;
[movie setContentURL:contentURL];
[movie prepareToPlay];
[self addSubview:moviePlayer.view];
I think its not possible. Please see the answer for this question
Playing Multiple Videos on iPAD
You will have to use AVPlayer for multiple video viewing, see this
Here is another tutorial for AVPlayer
You can also check this from apple developer portal, link
This question also says something about adding controls to AVPlayer
BR, Hari
Hi this is not possible to play more than 1 video in ios because only one thread at a time .
I face same issue in my iPad application but I've found an alternate solution.
I want to play more video in 1 view controller , but these videos are 4 to 5 sec's only.
I make number of continuous image frames of that video's and make .gif files and show this in a UIWebView. it works fine.

Can't play mp4 in Cocoa-Touch App

I am trying to play an mp4 after detecting a signal in the audio jack.
The video is playing once, after a delay of 1 sec which i dont want, and then application is freezing and i get this warning on the debugger: (only on the iphone, its working on simulation)
(8F190)/Symbols/System/Library/VideoDecoders/H264H4.videodecoder (file not found).
(8F190)/Symbols/System/Library/VideoDecoders/MP4VH4.videodecoder (file not found).
my code for the video is this :
//play video1
url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"sample1" ofType:#"mp4"]];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.useApplicationAudioSession=NO;
[moviePlayer prepareToPlay];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
[moviePlayer setMovieControlMode:MPMovieControlModeHidden];
moviePlayer.view.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:moviePlayer.view];
[moviePlayer play];
I couldnt find anything on this warning on the net.
I have tried any kind of video encoding,according to the Apple docs.
We just cant play movies, does anyone have any idea how to fix it?
thanks .
If you run that code twice, the video won't play the second time, because you are creating a second MPMoviePlayerController and a second view, and only one MPMoviePlayerController view in your app can play video. So it works the first time but not the second time. You should be retaining your MPMovieVideoController in a property so that you can remove its view and release the MPMovieVideoController before trying to make a new one.

Video not showing in iPhone Simulator (but I can hear audio from the video)

I am new to xcode, interface builder, and the iphone simulator. I am trying to play a movie/video in xcode on the click of a button (which is very straightforward). I am using xcode 3.2.4 and iphone simulator 4.1.
When I launch the iPhone simulator and click the button to launch the video, the audio plays, but the video is hidden. It's as if the video is behind the tab bar (this is part of a tab bar application). I am not sure how to make the video play in front.
Here's the code:
-(IBAction)launchVideo2:(id)sender{
NSString *movieFile;
MPMoviePlayerController *moviePlayer;
movieFile = [[NSBundle mainBundle]
pathForResource:#"IGDIs_Video_Picture_Naming_iPhone" ofType:#"mp4"];
moviePlayer = [[MPMoviePlayerController alloc]
initWithContentURL: [NSURL fileURLWithPath: movieFile]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(playMediaFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
[moviePlayer play];
}
-(void)playMediaFinished:(NSNotification*)theNotification
{
MPMoviePlayerController *moviePlayer=[theNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer release];
}
Any suggestions would be great!
should be using the MPMoviePlayerViewcontroller
see apple documentation
http://developer.apple.com/library/ios/#documentation/MediaPlayer/Reference/MPMoviePlayerController_Class/MPMoviePlayerController/MPMoviePlayerController.html
It doesn't look like you have added the movie view to your main view. You'll need to add something like:
...
[[moviePlayer view] setFrame:[self view] bounds]];
[[self view] addSubview:[moviePlayer view]];
[moviePlayer play];
}
before playing it. I'm assuming that the a launchVideo2 method is in a UIViewController that owns the main view. You might have to change [self view] to suit your code to correspond to the view where you want the movie to play.
In my experience, video won't display in the sim. However, audio will. (Which is an improvement, since previously neither would play.)
Try running the app on the device. If the video doesn't display there, post here and we'll work through the issue.
You have a probably unrelated memory issue there:
In your first method, you don't release the player, which is a local variable.
In your second method, you release the player, that you don't own.
Proper memory management (ie best practice), you would do this with an ivar.

Why does MPMoviePlayerController work in the simulator, but not the device?

I'm having trouble getting MPMoviePlayerController to work on the device. It runs fine in simulator, playing a five-second video and then sending the appropriate callback (myMovieFinishedCallback:) to the view controller. When it runs on the device, the movie never shows up, even though I can trace through [player play] with no problems. myMovieFinishedCallback: is never called, and there are no errors. All the right resources are being copied. Any idea what's going on?
Here's the code I use to create and use the player,
Update: I've switched over to using MPMoviePlayerViewController. On the device the movie still does not play, I just get the spinning progress wheel indefinitely. The controls also flash briefly even though I've set the player to MPMovieControlStyleNone - anybody know how I can fix this? The movie is five seconds and about 1.5 MB if that makes any difference.
Update: Other movie files work, but I can't figure out how to make mine work. I've tried it as a .mov and a .mp4 and the settings seem to be right. Any idea what would cause the MPMoviePlayer to show a progress wheel forever on the device only?
- (void) playMovie
{
NSString *url = [[NSBundle mainBundle]
pathForResource:#"myMovie"
ofType:#"mp4"];
MPMoviePlayerViewController *playerViewController =
[[MPMoviePlayerViewController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
playerViewController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerViewController.moviePlayer.scalingMode = MPMovieScalingModeFill;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:[playerViewController moviePlayer]];
playerViewController.view.frame = movieView.frame;
[movieView addSubview:playerViewController.view];
//---play movie---
MPMoviePlayerController *player = [playerViewController moviePlayer];
[player play];
}
Your code works fine for me, so there are two possibilities that come to mind (there may be others):
You movieView has not been properly initialized or has not had its frame set so that it's visible.
The video format of the video you're displaying isn't supported on the device.
I would try using a different video. Maybe one you can confirm you've played on the device before. Here's the little demo project I threw together: http://www.cimgf.com/files/PlayMovie.zip