It looks like you're new here. If you want to get involved, click one of these buttons!
#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
Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeDo not post moderator requests in public. Send a PM.
vvvvv----- Use the flag button to report spam.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome