Adding Navigationbar to MoviePlayer - iphone

I am trying to find out what I can do with an iPad as far as playing back video is concerned. And I have the following code for a UIButton action.
- (IBAction)playClick:(id)sender {
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"video3" ofType:#"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
}
As shown above, I do get a movie screen. I wonder if it's possible to include a navigation bar at the top (above 'Done') or the bottom (below the controller) of the movie screen so that I can add some actions while the user plays back video? I guess this topic may concern what I'm trying to do.
Thank you for your help.

You can add more buttons using,
UIBarButtonItem *button = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(yourButtonAction:)];
moviePlayer.navigationItem.rightBarButtonItem = button;
Customize these buttons as per your need.
Try this .Hope that make sense.
regards

Related

MPMoviePlayerViewController Issue-Iphone

I want to implement the movie player for that,i'm using MPMoviePlayerViewController.
My code is,
moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
moviePlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[self presentModalViewController:moviePlayerController animated:YES];
[[moviePlayerController moviePlayer] play];
but it's continuously loading and not playing the video.What i'm wrong with my code.
My requirement is,
In the movie player,when i'm click on the done button it goes to the page which i'm starting from.
Thank you for your consideration and effort
Edit:
Any sample code for using MPMoviePlayerController instead of using MPMoviePlayerViewController please give me.(please give me your implemented sample code because i can't understand the tutorial code)please help me
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"aaa" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(0, 70, 320, 270)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];

Playing a video in iOS app: audio but no picture

i want a short video to play in my iphone app. When i use the code below, i only hear the audio and see
the regular view of the app. I want the video to play on top of this view.
What can i do about this?
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"LEADER" 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];
Don't mix up MPMoviePlayerController and MPMoviePlayerViewController. When you use MPMoviePlayerController use it like this (typically for embedded videos on the iPad):
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player.view setFrame: myView.bounds]; // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];
When you use MPMoviePlayerViewController then present the video with presentMoviePlayerViewControllerAnimated: (typically for fullscreen videos).
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player.view.frame = self.view.frame];
[self.view addSubview: player.view];
// ...
[player play];
The only magic that worked for me was
- (void) playMovie {
NSURL *url = [NSURL URLWithString:
#"http://www.example.com/video.mp4"];
MPMoviePlayerController *controller = [[MPMoviePlayerController alloc]
initWithContentURL:url];
self.mc = controller; //Super important
controller.view.frame = self.view.bounds; //Set the size
[self.view addSubview:controller.view]; //Show the view
[controller play]; //Start playing
}
In Header file
#property (nonatomic,strong) MPMoviePlayerController* mc;
More Details

iPhone SDK: Stopping a Video

How can I stop a video once I navigate away from a view and make the video play again when I get back to the original view again?
Here is the code to play the video in the original view:
- (void)viewDidLoad {
NSBundle *bundle=[NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"Video" ofType:#"mp4"];
NSURL *movieURL=[[NSURL fileURLWithPath:moviePath] retain];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
theMovie.view.frame = CGRectMake(104.0, 134.0, 200.0, 250.0);
[self.view addSubview:theMovie.view];
[theMovie play];
[super viewDidLoad];
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
}
Make theMovie instance var
Stop playing in the -(void) viewWillDisappear:(BOOL)animated
And it should start playing when you navigate back to this view. Or move this code to -(void) viewDidAppear:(BOOL)animated

Adjust AVPlayer Frame Rate During Playback [duplicate]

I'm wondering if it's possible to change the video playback speed in an iphone application. we want users to yell in the microphone to speed up the playback and get to the end.
You have to use setCurrentPlaybackRate:
There is a rate property for the AVPlayer.
If you take the example from Apple called "avPlayerDemo" in the resource section, you then simply have to set the mplayer.rate. It worked for me, I created a new slider in the xib files, implemented that slider in the AVPlayerDemoPlaybackViewController and simply set mPlayer.rate to the slider value.
What about the MPMoviePlayerController?
setCurrentPlaybackRate
Here's some code which does not work at that spot
-(IBAction)abspielen:(id)sender
{
NSString *titleOfButton = [sender titleForState:UIControlStateNormal];
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:titleOfButton ofType:#"mov"];
NSURL *movieURL = [ NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *themovie = [[MPMoviePlayerController alloc]initWithContentURL: movieURL];
[themovie play];
[themovie setCurrentPlaybackRate:2.f];
[themovie release];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
[moviePlayer release];
}

How to play video locally in objective-c for iphone?

I want to play the video on iphone locally by storing the video in the app.
how can i do?
NSString *path = [[NSBundle mainBundle] pathForResource:#"myVideo" ofType:#"mp4"];
MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:path];
[self.view addSubview:myPlayer.view];
[myPlayer play];
To store video in the app, you can just add it with a copy files phase in the build. For an example of how to play a movie, check out the Media Player docs and especially the MoviePlayer sample code.
Try the following code:
-(IBAction)Videoplay_btn:(id)sender
{
NSString *videoPath = [[NSBundle mainBundle] pathForResource:#"Movie" ofType:#"m4v"];
NSURL *streamURL = [NSURL fileURLWithPath:videoPath];
MPMoviePlayerController *moviplayer =[[MPMoviePlayerController alloc] initWithContentURL: streamURL];
[moviplayer prepareToPlay];
[moviplayer.view setFrame: self.view.bounds];
[self.view addSubview: moviplayer.view];
moviplayer.fullscreen = YES;
moviplayer.shouldAutoplay = YES;
moviplayer.repeatMode = MPMovieRepeatModeNone;
moviplayer.movieSourceType = MPMovieSourceTypeFile;
[moviplayer play];
}
FYI
The MPMoviePlayerController class is formally deprecated in iOS 9.
(The MPMoviePlayerViewController class is also formally deprecated.)
To play video content in iOS 9 and later, instead use the
AVPictureInPictureController or AVPlayerViewController class from
the AVKit framework, or the WKWebView class from WebKit.