I using the below code to play video file using web service,but it is not work.please correct the code to play video.
NSBundle *bundle = [NSBundle mainBundle];
NSString *url = [NSString stringWithFormat:#"http://tnhd.in/load/2014/Anjaan/Oru%20Kan%20Jaadai%20BRrip%20-%20Anjaan%20HD.mp4"];
NSString *moviePath = [bundle pathForResource:url ofType:#"mp4"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2));
UIWindow *backgroundWindow = [[UIApplication sharedApplication] keyWindow];
[moviePlayer.view setFrame:backgroundWindow.frame];
[backgroundWindow addSubview:moviePlayer.view];
[moviePlayer play];
Just make the url like so:
NSString *path = #"http://tnhd.in/load/2014/Anjaan/Oru%20Kan%20Jaadai%20BRrip%20-%20Anjaan%20HD.mp4";
NSURL *url = [NSURL URLWithString:path];
Or better so:
NSURL *url = [NSURL URLWithString:#"http://tnhd.in/load/2014/Anjaan/Oru%20Kan%20Jaadai%20BRrip%20-%20Anjaan%20HD.mp4"];
and send it to your player
Related
I'm using this code to play local video, but control layout is broken:
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"simulation" ofType:#"mp4"]];
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
Kindly tell me how to play a .mp4 format video play in MPMoviePlayerController
NSString *urlStr=[[NSBundle mainBundle]pathForResource:#"Tour.mp4" ofType:nil];
NSURL *url = [NSURL fileURLWithPath:urlStr];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer.view];
moviePlayer.view.frame = CGRectMake(0,154,720,428);
[moviePlayer play];
Add MediaPlayer Framework
import it to your file
#import <MediaPlayer/MediaPlayer.h>
Create an object of MPMoviePlayerController
MPMoviePlayerController * moviePlayer;
write this code where you wants to play video
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"test.mp4" ofType:nil];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayer.view];
moviePlayer.fullscreen = YES;
[moviePlayer play];
try above code...
Does my app contain encryption with a video file? This is the code I have:
NSURL *url = [NSURL fileURLWithPath: [[NSBundle mainBundle] pathForResource:#"Video1" ofType:#"mp4"]];
MPMoviePlayerViewController *PlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
[self presentMoviePlayerViewControllerAnimated:PlayerController];
PlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[PlayerController.moviePlayer play];
PlayerController = nil;
Does my app contain encryption with the above code?
I am using the following code:
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"MovieName" ofType:#"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath isDirectory:NO];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.movieSourceType = MPMovieSourceTypeFile;
moviePlayerController.contentURL = fileURL;
moviePlayerController.fullscreen = YES;
[moviePlayerController prepareToPlay];
[moviePlayerController play];
However when the code is executed, the movie player appears, but the movie is never loaded.
For the sake of my own sanity, I added the following line:
NSData *thedata = [[NSData alloc]initWithContentsOfFile:filepath];
And I can verify the movie does exist, as it is loaded into the NSData object.
Where am I going working
TRY THIS :
NSString *filepath = [[NSBundle mainBundle] pathForResource:#"MovieName" ofType:#"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath isDirectory:NO];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
moviePlayerController.view.frame = self.view.bounds;
moviePlayerController.movieSourceType = MPMovieSourceTypeFile;
moviePlayerController.fullscreen = YES;
[self.view addSubview:moviePlayerController.view];
[moviePlayerController prepareToPlay];
[moviePlayerController play];
I've added this code to the viewDidLoad method:
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"myvid" ofType:#"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
[self.view insertSubview: moviePlayer.view aboveSubview: self.view];
[moviePlayer play];
it doesn't work! how can I play a video in the background of a view in iOS? (using storyboards)
It looks like the instance of MPMoviePlayerController you create is wounded by ARC during the playback.
Try making the strong property of MPMoviePlayerController and assign the instance you create there before starting playback.
So your code will look like this
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:#"myvid" ofType:#"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.moviePlayer.controlStyle = MPMovieControlStyleNone;
//set the frame of movie player
self.moviePlayer.view.frame = CGRectMake(0, 0, 200, 200);
[self.view addSubView:self.moviePlayer.view];
[self.moviePlayer play];