playing video iphone - mpmovieviewcontroller - iphone

I'm playing video with MPMoviePlayerViewController. I get video url from web service. But first I select video quality with AlertView. For example 240p 360p 480p… All video plays except 240p. MPMoviePlayerView appears and then disappears with notification MPMovieFinishReasonPlaybackEnded. I try to play url of 240p video in simulator, everything is perfect but in device it's not playing. I receive MPMovieFinishReasonPlaybackEnded all the time. If I select 360p or more, everything is good. Here is some code:
-(void) playVideoFromURL:(NSString *) url
{
NSLog(#"%#",url); //URL is valid! Browser plays it
if (!videoPlayerView) {
NSURL *fURL = [NSURL URLWithString:url];
videoPlayerView = [[MPMoviePlayerViewController alloc] initWithContentURL:fURL];
videoPlayer = videoPlayerView.moviePlayer;
[videoPlayer prepareToPlay];
}
}
It doesn't play even from the local folder. This is an iPhone app, my device is iPad 2!

Related

MPMoviePlayerController black screen when app enter foreground from background

I'm using an MPMoviePlayerController for playing video in my iPhone app.
When MPMoviePlayerController is playing, press home button on iPhone, make the app enter background.
Then tap the app's icon to make the app enter foreground, the MPMoviePlayerController's view will be black screen for a short time, about 1 to 15 seconds.
How to make the MPMoviePlayerController's video shows immediately when app came to foreground?
Special thx! :D
NSURL *movieURL = [NSURL URLWithString:#"http://......"];
// Initialize a movie player object with the specified URL
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[self.moviePlayer.view setFrame:self.view.bounds];
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer play];
I Hope this will help You.

Play a video from a server without exiting the app - Cocoa Touch, iPhone

Basically I have 8 thumbnails which are buttons. When each button is tapped, it launches the video which is located on my server. However at the moment, when a thumbnail is tapped, the video launches in safari and exits the app. I want it so the video launches in the app instead of exiting it, so once the user has finished watching the video, they are then returned to the app.
Here is the code I've used.
-(IBAction)goAbv1:(id)sender; {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://mywebsite.com/video.mp4"]];
}
Try this if you are on iOS 3.2+
NSString *videoURLString = #"http://MypathtoIphoneCompatibleVideoMp4";
NSURL *videoURL = [NSURL URLWithString:videoURLString];
MPMoviePlayerViewController *moviePlayerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:videoURL] autorelease];
[self presentMoviePlayerViewControllerAnimated:moviePlayerView];
presentMoviePlayerViewControllerAnimated will handle the modalviewcontroller and put it on top of the stack automatically so the video can be played. This should work easily.

MPMoviePlayerController interrupting playing audio

I'm developing an iPhone app that can play online videos and
I want to play an ad first when the video data is loading.
First, I request an AdColony video Ad and begin to play it, then use MPMoviePlayerController to load video data, But when the video is prepared to play, it interrupts the previous Ad sound, and causes the ad to stop.
Here are the codes Im using:
// Play Ad first
[AdColony playVideoAdForSlot:1 withDelegate:self]; // It also use MPMoviePlayerController to play video
// Load video for playing
moviePlayer = [[MPMoviePlayerController alloc]
init];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.shouldAutoplay = NO;
moviePlayer.view.frame = CGRectMake(0,44,320,320);
moviePlayer.view.userInteractionEnabled = YES;
[moviePlayer prepareToPlay]; // Interrupt Ad playing
The offical doc said "calling prepareToPlay may interrupt the movie player’s audio session", so the Ad was interrupted. If I remove prepareToPlay, the video data will not be preloaded
I have tried to put
[AdColony playVideoAdForSlot:1 withDelegate:self]; below [moviePlayer prepareToPlay];
but it does not work. Does anyone know how to resolve it?
There are ways to handle interruptions,
read through he Apples guide
http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/HandlingAudioInterruptions/HandlingAudioInterruptions.html#//apple_ref/doc/uid/TP40007875-CH11-SW1

AVAudioPlayer play little bit on vibrate mode in iOS sdk

i am develop app with avaudioplayer it's works perfectly, but,my problem is if my iPhone vibrate mode to open my app avaudioplayer plays audio little bit below seconds, i want to not play a avaudioplayer sound in vibrate mode.
here's my code:
- (void)viewDidLoad
{
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL
fileURLWithPath:[[NSBundle mainBundle]
pathForResource:#"audio" ofType:#"mp3"]] error:NULL];
audioPlayer.numberOfLoops =-1;
audioPlayer.delegate = self;
audioPlayer.currentTime=0.0f;
[audioPlayer prepareToPlay];
[audioPlayer Play];
}
can any one help me please..!
Thanks..!
Try:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryAmbient error: nil];
As stated in the Apple Docs:
AVAudioSessionCategoryAmbient
For an app in which sound playback is nonprimary—that is, your app can be used successfully with the sound turned off.
This category is also appropriate for “play along” style apps, such as a virtual piano that a user plays over iPod audio. When you use this category, audio from other apps mixes with your audio. Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone).
Should be what you're looking for specifically.
Your audio is silenced by screen locking and by the Silent switch (called the Ring/Silent switch on iPhone)

How to play video in portrait mode in iphone

I am creating a movie appliction in iphone/ipod .i have added a video to it . when i run it in simulator it runs properly in portrait mode.But when i run my app in ipod it opens a blank video and in landscape mode .but in simulator when i click on play my video directly plays in portrait mode and in ipod it opens a blank video in landscape mode which i want in portrait mode
This is my code for video:
-(IBAction)video1:(id)sender
{
NSBundle *bundle =[NSBundle mainBundle];
NSString *moviepath =[bundle pathForResource:#"CRY CRY - 90 Sec Video" ofType:#"mov"];
NSURL *movieURL =[[NSURL fileURLWithPath:moviepath]retain];
MPMoviePlayerController *theMovie =[[MPMoviePlayerController alloc]initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
MPMoviePlayerViewController *moviePlayer =[[MPMoviePlayerViewController alloc]initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}
Please help me in solving this problem.
What version of iOS is your iPod running? Version 3.x will always open videos in landscape mode, version 4.x will open videos in the current orientation.