0

I am porting app from iOS6 to iOS7. There is a weird problem that makes the screen go black after the call from a button is being done. I have tried out this, this and this.

There is no apt answer and I don't feel theoretically there should be any problem in using the previous methods.

Kindly provide me some thread to why this problem is occuring.

Thanks

Community
  • 1
  • 1
Xander
  • 902
  • 2
  • 14
  • 33
  • May I know why I got a down vote? – Xander Oct 21 '13 at 13:24
  • 1
    You tried three methods - all of them resulted into the same issue within your app, even though nobody else seemed to have that exact problem you are describing. That pretty much settles the fact that it is some other code you never showed us, triggering the problem. All answers that are given must be pure guesswork -> your question, as it stands is not useful, hence my down-vote. – Till Oct 21 '13 at 18:10

3 Answers3

1

This can help Import MediaPlayer in your .h file

#import <MediaPlayer/MediaPlayer.h>

Make a property

@property (strong, nonatomic) MPMoviePlayerController *moviePlayer;

After that you can play video by this

-(void)playMovie:(id)sender
{
  NSURL *url = [NSURL URLWithString:
  @"http://www.xyz.com/ios_book/movie/movie.mov"];

_moviePlayer =  [[MPMoviePlayerController alloc]
             initWithContentURL:url];

[[NSNotificationCenter defaultCenter] addObserver:self
               selector:@selector(moviePlayBackDidFinish:)
               name:MPMoviePlayerPlaybackDidFinishNotification
               object:_moviePlayer];

_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
}

After that for removing the video view add this

   - (void) moviePlayBackDidFinish:(NSNotification*)notification {
   MPMoviePlayerController *player = [notification object];
   [[NSNotificationCenter defaultCenter]
    removeObserver:self
    name:MPMoviePlayerPlaybackDidFinishNotification
    object:player];

  if ([player
    respondsToSelector:@selector(setFullscreen:animated:)])
 {
    [player.view removeFromSuperview];
 }
 }
souvickcse
  • 7,742
  • 5
  • 37
  • 64
-1

Add your movie player controller view on main windows like:

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: [NSURL URLWithString:@"map.mp4"]]; 

[player prepareToPlay]; 

[player.view setFrame: self.view.bounds];

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

[appDelegate.window addSubview: player.view];

[player play];

Hope so it will work for you!

Dilip Manek
  • 9,095
  • 5
  • 44
  • 56
Amol
  • 85
  • 5
  • This one will fail as soon as ARC is enabled. Additionally, it wont support reorientation. – Till Oct 21 '13 at 18:14
-2

Try this way..

ViewController.m

MPMoviePlayerViewController *mp=[[MPMoviePlayerViewController alloc]initWithContentURL:[NSURL fileURLWithPath:[[arr_videos objectAtIndex:indexPath.row]valueForKey:@"Video_path"]]];

MPMoviePlayerController *pc=[mp moviePlayer];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];

[self presentViewController:mp animated:YES completion:nil];
[pc prepareToPlay];
[pc play];
user1673099
  • 3,293
  • 7
  • 26
  • 57
  • This one is pure nonsense. You are allocating an `MPMoviePlayerViewController` and never assign it to the property that has been prepared within the header. – Till Oct 21 '13 at 18:14
  • This will fail when ARC is used. – Till Oct 22 '13 at 09:08