My application begins with a movie, and I am trying to swipe down or slide down to continue the movie but I don't know why the gesture doesn't work, I tried to use:
[player view].userInteractionEnabled = NO;
-(void) swiped: (UISwipeGestureRecognizer *) sender {
NSLog(#"SLIDE DOWN");
NSString *path = [[NSBundle mainBundle] pathForResource:#"sahar3" ofType:#"mov"];
player = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:path]];
player.moviePlayer.scalingMode = MPMovieScalingModeFill;
player.moviePlayer.controlStyle = MPMovieControlStyleNone;
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(movieFinishedPlaying:)
name:MPMoviePlayerPlaybackDidFinishNotification object:[player moviePlayer]];
player.moviePlayer.repeatMode = NO;
[self.view addSubview:player.view];
}
- (void)viewDidLoad
{
NSLog(#"lunched");
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swiped:)];
swipe.direction = UISwipeGestureRecognizerDirectionDown;
}
- (void)viewDidLoad
{
NSLog(#"lunched");
UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(swiped:)];
swipe.direction = UISwipeGestureRecognizerDirectionDown;
//add the following line in your application
[self.view addgesturerecognizer:swipe];
}
i think you forgot to add outlet on which you want to apply swipe gesture recognizer
Try implementing the – gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: delegate method and return YES.
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIGestureRecognizerDelegate_Protocol/Reference/Reference.html
Related
How can I resize the MPMoviePlayerController dynamically to fix all the size of screens for iPhone/iPad (both portrait & landscape)?
this is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
UIBarButtonItem *about = [[UIBarButtonItem alloc] initWithTitle:#"About" style:UIBarButtonItemStyleDone target:self action:#selector(openPopup)];
self.navigationItem.leftBarButtonItem = about;
NSURL *streamURL = [NSURL URLWithString:#"http:/streamUrl/playlist.m3u8"];
_streamPlayer = [[MPMoviePlayerController alloc] initWithContentURL:streamURL];
self.streamPlayer.controlStyle = MPMovieControlStyleEmbedded;
[self.view addSubview: self.streamPlayer.view];
[self.streamPlayer play];
}
I also tried to add
[self.streamPlayer.view setFrame:self.view.bounds];
but this makes the video is not fix to screen as shown in screenshot
How can I make it fix all screens of all different devices?
Thanks in advance.
The best solution I found is to use the following
CGFloat width = [UIScreen mainScreen].bounds.size.width;
CGFloat height = [UIScreen mainScreen].bounds.size.height;
[self.streamPlayer.view setFrame:CGRectMake(10, 10 ,height-20, width-70)];
i solved this problem in ios 5
as:
AvPlayerLayer *avPlayerLayer =[[AVPlayerLayer alloc]init];
avPlayerLayer = [[AVPlayerLayer playerLayerWithPlayer:avPlayer] retain];
avPlayerLayer.frame = self.playerView.layer.bounds;
avPlayerLayer.transform = CATransform3DMakeRotation(M_PI / 2.0, 0, 0, 1);
[self.playerView.layer addSublayer:avPlayerLayer];
here is avPlayerLayer.transform you can set it in any direction .
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:contentURL]];
if (moviePlayerViewController) {
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
[moviePlayerViewController.moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
if ([moviePlayerViewController.moviePlayer respondsToSelector:#selector(setAllowsAirPlay:)]) {
[moviePlayerViewController.moviePlayer setAllowsAirPlay:YES];
}
[[NSNotificationCenter defaultCenter] addObserverForName:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerViewController queue:nil usingBlock:^(NSNotification *notification) {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[self dismissMoviePlayerViewControllerAnimated];
}];
[moviePlayerViewController.moviePlayer play];
}
I have two view controllers, one is mainController second one is movieController...
After swiping back to mainController from movieController with [self.view removeFromSuperview]; video playing in movieController still plays as background sound.
I did release player, but no idea.
#synthesize viewForMovie,player;
- (void)viewDidLoad {
[super viewDidLoad];
//background image
self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:#"mits_bg.png"]];
//gesture recognizer -to up
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]
initWithTarget:self
action:#selector(handleSwipes:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionDown;
[self.view addGestureRecognizer:swipeGesture];
[swipeGesture release];
//movie player
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(movieDurationAvailable:)
name:MPMovieDurationAvailableNotification
object:nil];
**self.player = [[[MPMoviePlayerController alloc] init] autorelease];**
//self.player.controlStyle = MPMovieControlStyleNone; // no control at all :)
self.player.contentURL = [self movieURL];
self.player.view.frame = self.viewForMovie.bounds;
self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight ;
[self.viewForMovie addSubview:player.view];
[self.player play];
}
//---gesture recognizer
- (IBAction) handleSwipes:(UIGestureRecognizer *) sender {
UISwipeGestureRecognizerDirection direction = [(UISwipeGestureRecognizer *) sender direction];
if (direction == UISwipeGestureRecognizerDirectionDown) {
CATransition *transition = [CATransition animation];
transition.duration = 0.75;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromBottom;
transition.delegate = self;
// Next add it to the containerView's layer. This will perform the transition based on how we change its contents.
[self.view.superview.layer addAnimation:transition forKey:nil];
[self.view removeFromSuperview];
**self.player = nil;**
//[player release]; // I give it a try like this also
}
}
- (void)viewDidUnload {
[super viewDidUnload];
self.viewForMovie = nil;
self.player = nil;
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[thumbnailScrollView release];
[viewForMovie release];
[onScreenDisplayLabel release];
[player release];
[super dealloc];
}
You are retaining twice when you do this,
self.player = [[MPMoviePlayerController alloc] init];
You should add an autorelease message to this,
self.player = [[[MPMoviePlayerController alloc] init] autorelease];
I don't see a release called except for in viewDidUnload and dealloc. You should call it as soon as you remove the view from the superview. niling is a better option as your release call in dealloc will be on nil rather than a deallocated object. So after removing it from the view, make it nil like this,
self.player = nil;
I am using the MPMoviePlayerController to play a video on UIPopoverController.
When UIPopoverController dismiss video keeps on playing in background. Is there any way to stop and release MPMoviePlayer.
In my code There is FirstViewController and ViewVideoController which has function:
#implementation FirstViewController
- (void)popOverViewDisplay:(id)sender {
//if(![popoverController isPopoverVisible]){
NSLog(#"my popover....");
ViewVideoController *videoController = [[[ViewVideoController alloc] initWithNibName:nil bundle:nil] autorelease];
videoController.contentSizeForViewInPopover =CGSizeMake(550, 460);
popoverController = [[UIPopoverController alloc]
initWithContentViewController:videoController];
popoverController.delegate = self;
[videoController release];
popViewBtnFrame = CGRectMake(299, 357, 63, 42);
[popoverController presentPopoverFromRect:popViewBtnFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
if (self.popoverController != nil) {
[self.popoverController dismissPopoverAnimated:YES];
//[self.popoverController release];
NSLog(#" if loop popover dismissed");
ViewVideoController *videoController = [[ViewVideoController alloc] initWithNibName:#"ViewVideoController" bundle:nil];
[videoController unloading];
}
NSLog(#"popover dismissed");
}
on button press player start playing in popoverController.
#implementation ViewVideoController
- (void)viewDidLoad {
NSString *path = [[NSBundle mainBundle] pathForResource:#"AlphabetTrain" ofType:#"mov"];
NSURL *url = [NSURL fileURLWithPath:path];
player = [[MPMoviePlayerController alloc] initWithContentURL:url];
//player.movieControlMode = MPMovieControlModeHidden;
player.controlStyle = MPMovieControlStyleDefault;
player.view.frame = CGRectMake(75.0f, 80.0f, 400.0f, 300.0f);
[[self view] setCenter:CGPointMake( [[self view] bounds].size.width / 2, [[self view] bounds].size.height / 2)];
[self.view addSubview:player.view];
[player play];
//[player release];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(myMovieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[super viewDidLoad];
}
- (void)myMovieFinishedCallback:(NSNotification*)aNotification {
MPMoviePlayerController* player1 = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player1];
NSLog(#"stop player");
[player stop];
}
- (void)unloading { //this function called in firstviewcontroller to stop player on dismiss
NSLog(#"unloading player");
//[player endSeeking];
[self.player stop];
}
When I dismiss ViewVideoController player keeps on playing. Is there any way to stop/release player on dismiss of ViewVideoController
You can use delegate method
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
[moviePlayer stop];
}
I am initializing my gesture recognizers with the following code when I initialize a view. However, after multiple times of presenting a view on top of the one with the gesture recognizers and dismissing it with presentModalViewController and dismissModelViewController, the gesture recognizers stop working on the original view. I've tried manually releasing the recognizers in the view's dealloc function rather than using autorelease, but it doesn't seem to help. Does anyone have any ideas? Thanks!
Also, I should mention that this problem only happens on the device, and not the simulator.
-(void) initializeGestures {
recognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTapGesture:)] autorelease];
//recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(handleTapGesture:)];
[(UITapGestureRecognizer *)recognizer setNumberOfTouchesRequired:1];
[self.view addGestureRecognizer:recognizer];
recognizer.delegate = self;
swipeLeftGesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeGestureLeft:)] autorelease];
//swipeLeftGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeGestureLeft:)];
swipeLeftGesture.direction = UISwipeGestureRecognizerDirectionLeft;
[self.view addGestureRecognizer:swipeLeftGesture];
swipeLeftGesture.delegate = self;
swipeRightGesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeGestureRight:)] autorelease];
//swipeRightGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:#selector(handleSwipeGestureRight:)];
swipeRightGesture.direction = UISwipeGestureRecognizerDirectionRight; // default
[self.view addGestureRecognizer:swipeRightGesture];
swipeRightGesture.delegate = self;
}
-(IBAction) handleSwipeGestureLeft:(UISwipeGestureRecognizer*)sender
{
[self swipeLeft];
}
-(IBAction) handleSwipeGestureRight:(UISwipeGestureRecognizer*)sender
{
[self swipeRight];
}
-(IBAction) handleTapGesture:(UITapGestureRecognizer *) sender {
[self gotoDefinition];
}
did the view with gesture recognizers dealloc when you present another viewController?
this will cause the view remove gesture recognizers on it
I have a view controller which includes a MPMoviePlayer inside. I hide the navigation bar, and want it to be shown when the video paused.
When the video is loaded, it works just fine. After i paused the video navigation bar appears but it pushes the whole player view to a little bit down. How can i make navigation bar appear without affecting the player view.
here is the code i used:
In ViewDidLoad():
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(videoPlayerPlaybackStateChanged:)
name:MPMoviePlayerPlaybackStateDidChangeNotification
object:nil];
[self setWantsFullScreenLayout:YES];
[moviePlayer prepareToPlay];
//For viewing partially.....
moviePlayer.view.backgroundColor = [UIColor blackColor];
//[moviePlayer.view setFrame:CGRectMake(0, 0, 320, 410)];
[moviePlayer.view setFrame:[self.view bounds]];
moviePlayer.fullscreen = YES;
moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
[self.view addSubview:moviePlayer.view];
[moviePlayer play];
- (void) videoPlayerPlaybackStateChanged:(NSNotification*) aNotification
{
MPMoviePlayerController *player = [aNotification object];
if(player.playbackState == MPMoviePlaybackStatePaused){
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationController.navigationBarHidden = NO;
}
else if(player.playbackState == MPMoviePlaybackStatePlaying){
self.navigationController.navigationBarHidden = YES;
}
[player autorelease];
}
Thank you in advance...
In your condition
if(player.playbackState == MPMoviePlaybackStatePaused)
{
self.navigationController.navigationBar.tintColor = [UIColor blackColor];
self.navigationController.navigationBarHidden = NO;
}
Try using
[self.navigationController.navigationBar setTranslucent:YES];