How can I play a video in fullscreen, preventing the controls to appear when touching video (pause, play, etc)? Instead, when video is touched, I want to close it.
Can this be done?
Thanks in advance
MPMoviePlayerViewController *playerViewController=[[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:#"xyz" ofType:#"mp4"]]];
[self presentModalViewController:playerViewController animated:YES];
MpMoviePlayerController *player = [playerViewController moviePlayer];
player.controlStyle=MPMovieControlStyleNone; //hide the controls
[player play];
Related
I have some code that sets up an MPMoviePlayerController to play back a video stored in the app.
I follow the example code in Apple's documentation. However, the video plays even if I don't call -play on it as long as I have called -prepareToPlay.
NSURL *movieURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:_videoName ofType:#"mp4"]];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
[player setMovieSourceType:MPMovieSourceTypeFile];
[player setScalingMode:MPMovieScalingModeAspectFit];
[[player view] setFrame:[[self view] bounds]];
[[self view] addSubview:[player view]];
[player prepareToPlay];
//[player play];
Will play the video. I uncomment the -play and the same thing happens. It does not matter if I have -play in or not. And I had -prepareToPlay earlier in the code as well (before the view setup) and it did not make a difference.
This is on iOS8 of some sort. I have not tried other versions of iOS.
Why does it work like this? The Apple docs make it sound like it should not play until -play is called.
Try adding this line of code
player.shouldAutoplay = NO;
By default it is set to YES.
I'm new in iPhone Application Development, and now i faced a problem, can any one tell me how can i play a video randomly without pressing the play button. The video should start automatically while the application launch and play randomly without stopping. I don't have any idea how to do this. I don't have any code also. Please help me any one...
Thanks in advanced.
You could implement it like this:
You need a movie player configured with e.g. a file url and add it to your view
NSURL *url = [[NSBundle mainBundle] URLForResource:movieName withExtension:#"mov"];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.view.frame = // set the frame
[self.view addSubview:moviePlayer.view];
Start the movie player
[moviePlayer play];
Listen to the notification
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(handleMoviePlayerStatChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:moviePlayer];
Start the video again
- (void)handleMoviePlayerStatChange:(NSNotification *)note {
NSLog(#"mp playback state %i", moviePlayer.playbackState);
if (moviePlayer.playbackState == MPMoviePlaybackStatePaused) {
[moviePlayer play];
}
}
To hide the video controls set the controlStyle property of the movie player instance:
moviePlayer.controlStyle = MPMovieControlStyleNone;
I'm developing a iPhone app and need to play the animation video in the background. This video should run until the user touch's the screen of the app. Not exactly the screensaver but this should happen for the first time when the app is opened.
How can play the video file in the background and screen buttons on top of the video in the app?
Add video player in your view of subview and your view must be a transparent layer makes.
your app delegate check the user coming first time or not.
NSString *path = [[NSBundle mainBundle] pathForResource:#"testVideo" 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];
Simply add MPMoviePlayerController as background and play the video,
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: video_url];
[player prepareToPlay];
[player.view setFrame: requiredFrame];
[self.view addSubview: player.view];
After that, add tap gesture to whole view and remove player on tap gesture method..
I am trying to get a videostream to work.
My Code works super, it starts playing (fetches the Video From an url provided by Apple Support Sites - the player plays the first four seconds of the Video and then when this little status bar thing wants to automatically hide the player goes blackscreen (with Status bar I mean the indicator of Time, with the fullscreen Button etc.).
I cant Post sourcecode right now because I am writing with my iPhone, so I will do that later...
Hope That my description helps you to understand and maybe you can help me.
In my .h File:
MPMoviePlayerController *mp;
In my .m File:
NSURL *mediaURL = [NSURL URLWithString:#"http://km.support.apple.com/library/APPLE/APPLECARE_ALLGEOS/HT1211/sample_iTunes.mov"];
mp = [[MPMoviePlayerController alloc] init];
[mp setShouldAutoplay:YES];
[mp setMovieSourceType:MPMovieSourceTypeStreaming];
[mp setContentURL:mediaURL];
[mp setControlStyle:MPMovieControlStyleEmbedded];
[mp setFullscreen:NO];
[mp setScalingMode:MPMovieScalingModeNone];
[mp prepareToPlay];
mp.view.frame=CGRectMake(0, 0, 320, 220);
[self.view addSubview:mp.view];
this is working fine :)
I am having the toughest time playing a video after select anything from a UIImagePickerController when the UIImagePickerController is presented in a UIPopoverController.
Here is the code that presents the video:
-(void) presentMovie{
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"demo" ofType:#"mov"];
NSURL *movieURL = [NSURL URLWithString:filePath];
[[mp moviePlayer] setContentURL:movieURL];
[[mp moviePlayer] prepareToPlay];
[[mp moviePlayer] setShouldAutoplay:NO];
[[mp moviePlayer] setControlStyle:MPMovieControlStyleEmbedded];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[[mp moviePlayer] setAllowsAirPlay:YES];
[[mp view] setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[screen addSubview:mp.view];
[[mp view] setFrame:screen.bounds];}
mp is a MPMoviePlayerViewController ivar that is allocated and initialized in my viewDidLoad
[self presentMovie] works perfectly unless it is being called from within the -imagePickerController:didFinishPickingMediaWithInfo: method
When called from that delegate methode, the video being displayed by MPMoviePlayerVideoController simply disappears from as soon as it is played. If the 'shouldAutoPlay' property is set to YES, I just see loading for a split second and then blackness. If the 'shouldAutoPlay' property is set to NO, then I see the first frame of the video, and I can scrub to a different location in the vido, take the video in and out of full screen, etc. but soon as I hit play, the view that the video is in goes black. This is true if the video that I'm attempting to play is from the UIImagePickerController selection or from the mainBundle. Once the UIImagePicker is selected, the video will not play.
I have gone through several steps of debugging and this does not happen with the UIImagePickerControll is presented in a modal view on the iPhone only when it's in a UIPopoverController on the iPad.
any ideas? anyone else able to successfully play a video on the iPad selected from a UIImagePickerController?
Turns out the answer is "roll your own" using ALAsssetsLibrary. UIImagePickerContorller doesn't work with video on iPads, and creating your own custom picker isn't too hard. There's sample code from the WWDC 2010 as well as code from Mat Tuzzolo on GitHub https://github.com/elc/ELCImagePickerController
I had this problem, that the video would not play after being picked from UIImagePickerController, but I wasn't fully releasing the popover. When I released it properly, it worked fine.
Thanks to prudence # UIImagePickerController choosing video prevents MPMoviePlayerViewController instance from working