2011年5月28日土曜日

iPhoneシミュレータでVideoを再生する





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

@interface videoPlayerViewController : UIViewController {

}

-(IBAction) playVideo;

@end


videoPlayerViewController.m
#import "videoPlayerViewController.h"

@implementation videoPlayerViewController

-(IBAction) playVideo{

 NSBundle *bundle = [NSBundle mainBundle];
 NSString *filePath = [bundle pathForResource:@"video" ofType:@"mp4"];
 NSURL *fileURL = [[NSURL fileURLWithPath:filePath] retain];
 MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
 theMovie.scalingMode = MPMovieSourceTypeFile;
 MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
 [self presentMoviePlayerViewControllerAnimated:moviePlayer];
}

- (void)didReceiveMemoryWarning {
 // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
 
 // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
 // Release any retained subviews of the main view.
 // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

@end


参考

YouTube - Xcode Tutorial 1 - How to play videos in 4.0 or Higher
http://www.youtube.com/watch?v=EJsyrdzpIbA&hd=1

0 コメント: