How to play a video in iPhone simulator
-
29-06-2021 - |
Question
I want to play a video in the iPhone simulator. I have tried with MPMoviePlayerViewController, but its not playing. Anybody has an idea on how to do it ? If there is any good tutorial , please help me find one. Thanx.
NOTE: Question related to MPMoviePlayerViewController not MPMoviePlayerController
La solution
Just drag and drop the video file in Your Xcode project
Give the url of video in "videourl"
NSURL *url = [NSURL URLWithString:videourl];
MPMoviePlayerViewController *moviePlayer1 = [[MPMoviePlayerViewController alloc]initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayer1];
It will run perfectly in simulator
This link Can also help You
Autres conseils
Assuming ARC.
You can for example call that in your viewDidLoad method and add that controller to your view using:
- (void)viewDidLoad
{
[super viewDidLoad];
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"test" ofType:@"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.scalingMode = MPMovieScalingModeAspectFill;
[theMovie play];
[self.view addSubview:theMovie.view];
[self addChildViewController:theMovie];
}
in my header file I write:
MPMoviePlayerController *moviePlayer;
with this property:
@property(nonatomic, strong) MPMoviePlayerController *moviePlayer;
and in the method in which I init the moviePlayer:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePlayer = player;
Use the following code
MPMoviePlayerController *moviePlayer1 = [[MPMoviePlayerController alloc]
initWithContentURL:yourVideoURL];
moviePlayer1.view.frame = CGRectMake(0, 0, 200, 110);
[self.view addSubview:moviePlayer1.view];
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer1];
[moviePlayer1 play];
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow