I am using MPMoviePlayerViewController to play video. I have added following piece of code, However its not playing. View is presenting with black screen and hiding immediately without playing.
MPMoviePlayerViewController *moviePlayerVC = [[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL URLWithString:#"/Users/gui_test/Desktop/273_0.mp4"]];
moviePlayerVC.moviePlayer.allowsAirPlay = YES;
moviePlayerVC.view.backgroundColor = [UIColor blackColor];
[self presentMoviePlayerViewControllerAnimated:moviePlayerVC];
[moviePlayerVC.moviePlayer play];
Am I need to do anything more to play a mp4 file Note: I am trying in simulator. Is it possible to play a (.mp4) file in Simulator.
I have used MPMoviePlayerController instead of MPMoviePlayerViewController:
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:songUrl];
[[self.moviePlayer view] setBounds:CGRectMake(0, 0, 320, 480)];
[moviePlayer.backgroundView setBackgroundColor:[UIColor blackColor]];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
[moviePlayer setScalingMode:MPMovieScalingModeNone];
[moviePlayer prepareToPlay];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:NO];
Try this this should work.
Try this code :) , and I guess it supports .mov files only and your video isn't playing cause its mp4
NSString*thePath=[[NSBundle mainBundle] pathForResource:#"filename" ofType:#"mov"];
NSURL*theurl=[NSURL fileURLWithPath:thePath];
NSLog(#"the url= %#",theurl);
moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:theurl];
[moviePlayer.view setFrame:CGRectMake(0, 0, 320, 480)];
[moviePlayer prepareToPlay];
[moviePlayer setFullscreen:YES];
[moviePlayer setShouldAutoplay:YES];
[self.view addSubview:moviePlayer.view];
Related
I am playing video in MPMoviePlayer in my app,I am fetching the video from server.
If the video length is about 25sec or more,the audio gets break.Means while playing the video when it reaches half then there is no audio can be heared.But if I seek the progess bar,audio again comes.
Can any one help me in this ?
moviePlayerController = [[MPMoviePlayerController alloc] init];
[moviePlayerController prepareToPlay];
moviePlayerController.shouldAutoplay = YES;
[moviePlayerController setScalingMode:MPMovieScalingModeAspectFit];
[[self.moviePlayerController view] setFrame:CGRectMake(0, 72, 320,180)];
[[self view] addSubview: [self.moviePlayerController view]];
self.moviePlayerController.useApplicationAudioSession = YES;
NSString *strng = #"http://qdemo_videos.s3.amazonaws.com/1360582540.mp4";
NSURL * adurl = [NSURL URLWithString:strng];
moviePlayerController.contentURL = url;
moviePlayerController.controlStyle = YES;
self.moviePlayerController.useApplicationAudioSession = YES;
[moviePlayerController play];
If u are building on Xcode 4.6 or above and using iOS 6.0 or above then,
self.moviePlayerController.useApplicationAudioSession = YES;
will not be called as its deprecated.
For further use this link:
Here's the doc
http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVAudioSession_ClassReference/Reference/Reference.html
Here's the explanation http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Configuration/Configuration.html
And if it's not enough here is the code :) http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Cookbook/Cookbook.html#//apple_ref/doc/uid/TP40007875-CH6-SW2
In my case setting the category to AVAudioSessionCategoryAmbient did the trick!
I'm trying to add a video that I pull from my server do play in my app.
The video plays now, but I don't have any UI controls for volume. fullscreen etc.
Can any one help? Here is my code
NSURL *url = [NSURL URLWithString:#"http://www.gzerodesign.com/sharksclips/video.mp4"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
if ([moviePlayer respondsToSelector:#selector(setFullscreen:animated:)]) {
// Use the new 3.2 style API
moviePlayer.controlStyle = MPMovieControlModeDefault;
moviePlayer.shouldAutoplay = YES;
[[moviePlayer view] setFrame:[[self view] bounds]];
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
[moviePlayer play];
} else {
// Use the old 2.0 style API
moviePlayer.movieControlMode = MPMovieControlModeHidden;
[moviePlayer play];
}
I only have experience the New 3.2 style API.
moviePlayer.controlStyle = MPMovieControlModeDefault;
comment out
// moviePlayer.controlStyle = MPMovieControlModeDefault;
you may be have fullscreen button and skip button.
but not show volume.
I did not try but, I search this.
MPMoviePlayerViewController not showing volume slider?
Delete this line in your code:
moviePlayer.controlStyle = MPMovieControlModeDefault;
& also this line:
moviePlayer.movieControlMode = MPMovieControlModeHidden;
& then check.
In my iPhone App I want to play video in a small view.
Video should start playing automatically, and the buttons for play pause and full screen should be hidden.
How can I achieve that?
What you would do is manually set the frame for MPMoviePlayerController's view, and set the control style to MPMovieControlStyleNone. Much like this below..
....
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
[player setControlStyle:MPMovieControlStyleNone];
//this is where you create your `embedded` view size
player.view.frame = CGRectMake(0, 0, 200, 300);
[self.view addSubview:player.view];
....
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] init];
[player prepareToPlay];
player.shouldAutoplay = NO;
player.allowsAirPlay = YES;
player.scalingMode = MPMovieScalingModeAspectFit;
[player.view setFrame:CGRectMake(0,0,300,320)];
[viewPlayer addSubview:player.view];
self.moviePlayer = player;//declare MPMoviePlayerController class object globaly for play and push the vedio if you want to add this functionality
hope,this help you....
:)
I have written this piece of objective-c code for playing a video after touching an image.
//start video here
NSString *path = [self localVideoPath:NO];
// Create custom movie player
MPMoviePlayerController *moviePlayer = [[[MPMoviePlayerController alloc] initWithPath:path] autorelease];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(onMSAASDone:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
[moviePlayer setFullscreen:FALSE];
//---play partial screen---
moviePlayer.view.frame = CGRectMake(0, 0, 200, 300);
//[[moviePlayer view] setFrame: [image bounds]];
[self.view addSubview:moviePlayer.view];
// Show the movie player as modal
//[self presentModalViewController:moviePlayer animated:YES];
// Prep and play the movie
[moviePlayer play];
The problem is that the code stops working at second line of statement. The error is... Program GDB: Received Signal: "EXC_BAD_ACCESS"
Help Me Please!
MPMoviePlayerController *moviePlayer = [[[MPMoviePlayerController alloc] initWithPath:path] autorelease];
the function initWithPath is not the part of MPMoviePlayerController class,
i could not find it in documentation.
May be you were trying to use
- (id)initWithContentURL:(NSURL *)url
plz read the apple documentation.
http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html
I am using MPMoviePlayerController currently to play a video inside IPhone and now I wish to play this video in a small area of the view (not the full screen). I think there is a frame way of doing it but I couldn't find the required tutorial somewhere. Have you been across any? That would be great.
UPDATED
I have reached to this point but still it doesn't show the player to play on screen.
-(IBAction)startVideo {
//start video here
NSURL *path = [[NSURL alloc] initWithString:[self localVideoPath:NO]];
// Create custom movie player
MPMoviePlayerController *moviePlayer = [[[MPMoviePlayerController alloc] initWithContentURL:path] autorelease];
[moviePlayer setScalingMode:MPMovieScalingModeAspectFill];
[moviePlayer setControlStyle:MPMovieControlStyleNone];
[moviePlayer setFullscreen:FALSE];
// May help to reduce latency
[moviePlayer prepareToPlay];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(onMSAASDone:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
//---play partial screen---
//moviePlayer.view.frame = CGRectMake(0, 0, 200, 300);
moviePlayer.view.frame = image.frame;
//[[moviePlayer view] setFrame: [image bounds]];
[image removeFromSuperview];
[self.view addSubview:moviePlayer.view];
// Show the movie player as modal
//[self presentModalViewController:moviePlayer animated:YES];
// Prep and play the movie
[moviePlayer play];
}
Here is 'windowed' code...
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc]
initWithContentURL:[NSURL fileURLWithPath:url]];
[player setControlStyle:MPMovieControlStyleNone];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player setScalingMode:MPMovieScalingModeAspectFill];
[player setFullscreen:FALSE];
//---play partial screen---
player.view.frame = CGRectMake(0, 0, 200, 300);
[self.view addSubview:player.view];