Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <UIKit/UIKit.h>
- #import <MediaPlayer/MediaPlayer.h>
- @interface BigBuckBunnyViewController : UIViewController {
- }
- -(IBAction)playMovie:(id)sender;
- @end
- #import "BigBuckBunnyViewController.h"
- @implementation BigBuckBunnyViewController
- -(IBAction)playMovie:(id)sender
- {
- UIButton *playButton = (UIButton *) sender;
- NSString *filepath = [[NSBundle mainBundle] pathForResource:@"ladder rack 1 4"
- ofType:@"m4v"];
- NSURL *fileURL = [NSURL fileURLWithPath:filepath];
- MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc]
- initWithContentURL:fileURL];
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(moviePlaybackComplete:)
- name:MPMoviePlayerPlaybackDidFinishNotification
- object:moviePlayerController];
- [moviePlayerController.view setFrame:CGRectMake(playButton.frame.origin.x,
- playButton.frame.origin.y,
- playButton.frame.size.width,
- playButton.frame.size.height)];
- [self.view addSubview:moviePlayerController.view];
- //moviePlayerController.fullscreen = YES;
- //moviePlayerController.scalingMode = MPMovieScalingModeFill;
- [moviePlayerController play];
- }
- - (void)moviePlaybackComplete:(NSNotification *)notification
- {
- MPMoviePlayerController *moviePlayerController = [notification object];
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:MPMoviePlayerPlaybackDidFinishNotification
- object:moviePlayerController];
- [moviePlayerController.view removeFromSuperview];
- [moviePlayerController release];
- }
- - (void)dealloc {
- [super dealloc];
- }
- @end
- NSURL *fileURL = [NSURL fileURLWithPath:filepath] absoluteString];
- #import <UIKit/UIKit.h>
- #import <MediaPlayer/MediaPlayer.h>
- @interface TipsViewController : UIViewController {
- MPMoviePlayerViewController *playerController;
- }
- -(IBAction)playVideo;
- @end
- - (IBAction)playVideo{
- NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"tcniche"
- ofType:@"mp4"]];
- if(url != nil){
- playerController = [[MPMoviePlayerViewController alloc]
- initWithContentURL:url];
- [self presentMoviePlayerViewControllerAnimated:playerController];
- playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
- [playerController.moviePlayer play];
- }
- else{
- NSLog(@"URL not found");
- }
- }
Add Comment
Please, Sign In to add comment