Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Unable to remove MPMoviePlayerController after video is finished ios 6

geestringgeestring Posts: 23Registered Users
I've been pulling my hair out trying to get this simple video player to work.

I just want my video to play full screen then remove itself when it's done. It looks simple but I can't seem to get this to work right in the ipad ios 6 simulator.

Does anyone have an example that they know works?



#import <UIKit/UIKit.h>
#import <MediaPlayer/MediaPlayer.h>

@interface ViewController : UIViewController{
MPMoviePlayerController *movie;
}
@property (retain, nonatomic) MPMoviePlayerController *movie;

-(IBAction)playMovie:(id)sender;
- (void)moviePlaybackComplete:(NSNotification *)notification;
@end


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize movie;


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

UIButton *video_btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
video_btn.frame = CGRectMake(0, 0, 100, 50);
[video_btn setTitle:@"Moonrise" forState:UIControlStateNormal];
[video_btn addTarget:self action:@selector(playMovie:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:video_btn];



}

-(IBAction)playMovie:(id)sender
{

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"moonrise" ofType:@"mp4"]];
self.movie = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:self.movie];



[self.view addSubview:self.movie.view];
[self.movie setFullscreen:YES animated:YES];



[self.movie play];


}

- (void)moviePlaybackComplete:(NSNotification *)notification
{

MPMoviePlayerViewController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];



}



- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end

Post edited by geestring on

Replies

Sign In or Register to comment.