Reputation: 23
How To play Server URL Video in Iphone ?
how to play video from url using MPMoviePlayer
?
(void)loadVideo {
videoUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://movies.apple.com/media/us/mac/getamac/2009/apple-mvp-biohazard_suit-us-20090419_480x272.mov"]];
if(videoUrl) {
if([videoUrl scheme]) {
[self playVideoStream:videoUrl];
}
}
}
-(void)playVideoStream:(NSURL *)movieFileURL {
MPMovieSourceType movieSourceType = MPMovieSourceTypeUnknown;
/* If we have a streaming url then specify the movie source type. */
if ([[movieFileURL pathExtension] compare:@"mov" options:NSCaseInsensitiveSearch] == NSOrderedSame)
{
movieSourceType = MPMovieSourceTypeStreaming;
}
[self createAndPlayMovieForURL:movieFileURL sourceType:movieSourceType];
}
-(void)createAndPlayMovieForURL:(NSURL *)movieURL sourceType:(MPMovieSourceType)sourceType {
/* Play the video! */
[moviePlayer setMovieSourceType:sourceType];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];;
moviePlayer.view.frame = CGRectMake(10, 20, 280, 210);
[customVideoView addSubview:moviePlayer.view];
[moviePlayer play];
}
Upvotes: 1
Views: 2173
Reputation: 7
try this:
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"//name of your video here" ofType:@"//format e.g. mp4, m4v"]];
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:playerController];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[playerController.moviePlayer play];
// When movie finished loading you can have a notification and do extra code
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MovieDidLoad:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[playerController release];
playerController = nil;
}
-(void)MovieDidLoad:(NSNotification *)notification {
NSLog(@"logged and notification is %@", notification);
// extra code if needed
}
Upvotes: 1
Reputation: 29767
You need to set contentURL
property at fisrt
moviePlayer.contentURL = urlVideo;
[moviePlayer prepareToPlay];
[moviePlayer play];
Upvotes: 2