How to play video file in MPMOviePlayer? - iphone

I have implementing uITabbar application in which i want to play video file.Video file is playing but not seen.And simulator is Landscapmode bu MPMoviePlayer in Potrait mode.How to solve this problem.

Try to play the mp4 format.Because MPMoviePlayer Controller does not support many formats like avi.Here is the code which i implement.Hope it will help you and download any mp4 video file to play.
NSString *soundFilePath = [[NSBundle mainBundle]pathForResource:#"SoundFileName" ofType:#"mp4"];
//NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];
NSURL *fileURL=[[NSURL fileURLWithPath:soundFilePath]retain];
player = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[fileURL release];
[player play];

Related

How to Play Streaming Audio in UITableView

I have searched relentlessly but with no luck.
I am simply trying to play streaming audio files (mp3) in my tableview (didSelectRowAtIndexPath) but their is no error in xcode but the mp3 wont play
Here is a snippet
NSString *urlstr = #"www.nosajsolomon.com/pull_up_to_mi_bumper.mp3";
NSURL *url = [NSURL URLWithString:urlstr];
AVPlayerItem *playerItem2 = [AVPlayerItem playerItemWithURL:url];
player = [AVPlayer playerWithPlayerItem:playerItem2];
[player play];
player.actionAtItemEnd = AVPlayerActionAtItemEndNone;
Any idea what I am doing wrong?

MPMoviePlayerController Endless Loading

I'm trying to play an MP4 file with the MPMoviePlayerController (also tried two m4v files, same problem), and finally got the video player to come up, but it just stays loading. Here's my code, executed on a button press:
NSString *videoFile = [[NSBundle mainBundle] pathForResource:#"attn8" ofType:#"mp4" inDirectory:#""];
NSURL *url = [NSURL fileURLWithPath:videoFile isDirectory:NO];
player = [[MPMoviePlayerController alloc] initWithContentURL:url];
player.movieSourceType = MPMovieSourceTypeFile;
//put on a whim from another answer, made no difference
[self.view addSubview:[player view]];
player.fullscreen = true;
[player prepareToPlay];
[player play];

play video using url ios 6

I am struggling to play a video which is a url of the video file on a server. I have a view in which I display url from the web service. When I click the url(contained in a table cell) I want that a new view should appear with movie player on it playing the video. I have tried MPMoviePlayerViewController and also MPMoviePlayerController and various combinations of the two but I could not play the video on simulator. Currently I don't have a device so please consider simulator as well as device while answering. Currently i am using:
NSURL *url = [NSURL fileURLWithPath:filePath];
self.player= [[ MPMoviePlayerViewController alloc] initWithContentURL:url];
//self.player.navigationController.navigationBar.hidden = YES;
[self.player.moviePlayer prepareToPlay];
//self.player.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
self.player.moviePlayer.controlStyle = MPMovieControlStyleNone;
self.player.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.player.moviePlayer.fullscreen = NO;
[self presentModalViewController:self.player animated:NO];
[self.player.moviePlayer play];
filepath is a nsstring containing the video url.
Replace your this line : NSURL *url = [NSURL fileURLWithPath:filePath];
with this: NSURL *url=[NSURL URLWithString:filePath]; & then try.
My Code I am using MPMOVIEPLAYERVIEWCONTROLLER:
NSData *geturl = [[videoparsing objectAtIndex:btntag]objectForKey:#"iurl"];
myString = [[NSString alloc] initWithData:geturl encoding:NSASCIIStringEncoding];
NSLog(#"myString..%#",myString);
NSURL *fileURL=[NSURL URLWithString:myString];
NSLog(#"fileURL..%#",fileURL);
moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayerController];
[moviePlayerController.moviePlayer prepareToPlay];
moviePlayerController.moviePlayer.shouldAutoplay=YES;
[moviePlayerController.moviePlayer play];
If video file is on server then
NSURL *url=[NSURL URLWithString:filePath];
other should be change movieSourceType to MPMovieSourceTypeStreaming :
self.player.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
Also
self.player.moviePlayer.fullscreen = YES;
EDIT : Add :
self.player.moviePlayer.shouldAutoplay=YES;
remove :
[self.player.moviePlayer play];

iPhone video gets displayed in lower right hand corner when orated from vertical to horizontal

When my app runs, the video and the phone is rated to landscape mode, my video then plays in the lower right hand corner, is there a way to have the video be in the middle of the screen when the user rotate it?
I'm not sure how you're running your video, but try doing it like this (after importing MediaPlayer/MediaPlayer.h):
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"ExampleVideo" ofType:#"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *testMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
testMovie.scalingMode = MPMovieScalingModeAspectFit;
[testMovie play];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
I call that when I play movies and it works fine with rotations.

Problem with AVAudioPlayer ? Creating delay

While using AVAudioPlayer .... Sound not playing at instant if i click button... and in that class i have one NSTimer which keep changing image so for that purpose i have to ring sound.
But If i will use this AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath: soundPath], &soundID);... i am not able to hear sound in device.. cause my file is in mp3 format.
AVAudioPlayer Code:
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#/slotmachine.mp3", [[NSBundle mainBundle] resourcePath]]];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
audioPlayer.numberOfLoops = -1;
[audioPlayer play];
So anyone can tell me why i am not able to use AVAudioPlayer so smoothly like System Sound does.. what is the appropriate way to integrate ?
Call [audioPlayer prepareToPlay] well before you want to actually play the audio.