I want to create an app which has a default image as the background of a view that has many buttons on it. When a user clicks on any of the buttons, a unique video plays. The buttons are gonna be almost transparent so, I want the video to play in the background of the same view itself (replacing/playing above the image) and not open in a new Player(as it does using the media player). Has anyone tried it, or does anyone have any idea?
Thank You!
#import <MediaPlayer/MPMoviePlayerController.h>
MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL fileURLWithPath: moviePath]];
moviePlayer.controlStyle = MPMovieControlStyleNone;
[RootViewController.view insertSubview: moviePlayer.view aboveSubview: myView];
[moviePlayer play];
Related
I am trying to add a video to a view controller. I tried using the AVPlayerViewController but i was not able to achieve the result i wanted. I do not want the video to open in a new view controller. Instead i want it to be playing in the background. There will be buttons in the foreground and the user can press it. Here is a picture of how the page is supposed to look like.
The globe will be rotating and the user can login or sign-up. From what i have researched i understand that it is only possible through using a gif. But how is youtube able to achieve this? Is it possible for me to do so?
you need to add video first to your main view using Avplayer like following:
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"Untitled" ofType:#"mp4"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
avPlayer = [AVPlayer playerWithURL:fileURL];
layer = [AVPlayerLayer playerLayerWithPlayer:avPlayer];
avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
layer.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view.layer addSublayer: layer];
Then u need to create UiView with 2 button as you specify "Login" and "Sign-Up" and make Uivew BackgroundColor Property:clear color. and add this code to place view on your main view.
CGRect viewframe=self.buttonView.frame;
viewframe.origin.x=0;
viewframe.origin.y=0;
viewframe.size.height=self.view.frame.size.height;
viewframe.size.width=self.view.frame.size.width;
self.bnuttonView.frame=viewframe;
[self.view addSubview:self.buttonView];
In this way your video will play in background and Login and Sign-up button are working in foreground.
I want to play video in MPMoviePlayerViewController, it works fine and plays video but problem is that it does not show done button unless i switch to the full screen mode. It should automatically show player along with done button as shown in attached screen.
here is the code:
mp = [[MPMoviePlayerViewController alloc] initWithContentURL:myURL];
[[mp moviePlayer] prepareToPlay];
[[mp moviePlayer] setUseApplicationAudioSession:NO];
[[mp moviePlayer] setShouldAutoplay:YES];
[[mp moviePlayer] setControlStyle:2];
[self presentMoviePlayerViewControllerAnimated:mp];
Done button will be visible only when video is played in full screen mode. So, either you need to play the video in full screen mode using the following code:
player.moviePlayer.fullscreen = YES;
Or you need to customise the control to add your own Done button.
Done button visible you set the ControlStyle.
[player.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[player.moviePlayer setFullscreen:NO animated:YES];
Here's one I haven't been able to find an answer to. I am creating an iPhone (iOS 5.0) app and have used MPMoviePlayerController to get a thumbnail frame for video clips which I display in a gallery that contains thumbnails for both images & videos (just like the Photos app).
In the Photos app, for video thumbnails, it shows a little toolbar with a movie camera icon and the length of the clip, to indicate the thumbnail is a video. I can't figure out how to add this to my video frame thumbnails. Do I have to create something like that toolbar and add it to the UIImage of the frame thumbnail myself, or is there something here that I've just missed?
Thanks in advance.
I get the solution for your question...
So , you can use this: `
[yourButton setBackgroundImage:[self getVideoThumbnail:urlFromVideo]
forState:UIControlStateNormal];
[yourButton setImage:[UIImage imageNamed:yourImageName] forState:UIControlStateNormal];`
Function to getThumbnail is here:
- (UIImage *)getVideoThumbnail:(NSURL *)videoURL
{
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];
//Player autoplays audio on init
[player stop];
return thumbnail;
}
I think this is the option for you...
I embedded a MPMoviePlayerController on my mail view. I can play/pause the movie and seek forward/backward. But when I touch the "fullscreen button" the movie stops and the playback state is set to MPMoviePlaybackStateStopped... Should the movie be played in full screen?
Here is my code:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
player.shouldAutoplay = NO;
player.movieSourceType = MPMovieSourceTypeFile;
player.controlStyle = MPMovieControlStyleEmbedded;
player.allowsAirPlay = YES;
player.view.frame = CGRectMake(xPos, yPos, width, height);
[self.view addSubview:player.view];
I found my bug: when pressing the full screen toggle button in MPMoviePlayerController's view, the method "viewWillLayoutSubviews" is invoked. I could never imagine this behavior...
I hope my experience can be useful to other developers.
Remember that any containing ViewController will have its viewWillDisappear, viewDidDisappear methods invoked when the MPMoviePlayerController goes full screen. Also, viewWillAppear and viewWillDisappear get called when it comes back from full screen.
If you have any logic in there that affects video playback behavior, it'll get called unless you use some conditional logic to see if the video is still playing.
I have strange problem with MPMoviePlayerController. When movie starts , top bar with done button & controls remain visible for few seconds.Then disappears.
I am using
[player setControlStyle:MPMovieControlStyleFullscreen];
[player setFullscreen:YES];
player is an object of MPMoviePlayerController
I just want movie to play in full screen with top bar & controls hidden
& become visible only if user taps the screen
I am using iOS 4.0
try this
before starting the video
player.controlStyle = MPMovieControlStyleNone;
and when movie starts playing then set
player.controlStyle = MPMovieControlStyleFullscreen;
You can get play callback from MPMediaPlayback protocol.