i am trying to Load video from Path in my file system Project , i have code for the URL stream
NSString *path = [[NSBundle mainBundle] pathForResource:#"US_Very_High_Dive_Boudia_US_44_x264" ofType:#"mp4"];
NSData *data = [[NSData alloc] initWithContentsOfFile:path];
MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
You don't. MPMoviePlayer knows best when to load data. Convert the file path to a NSURL, or even better, just use
NSURL *myURL =`[[NSBundle mainBundle] URLForResource:#"US_Very_High_Dive_Boudia_US_44_x264" withExtension:#"mp4"];`
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL: myURL];
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];
I am working in an iOS project. I want may application to download a video from the internet programmatically. Then I want to play it. I know how can I play a local video from the Resources, but my question is how could I download it , and the find it to be played.
I am using MPMoviePlayerController to run the video.
Thanking in advance
I found the answer
here I saved the video
NSString *stringURL = #"http://videoURL";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
NSString *documentsDirectory ;
if ( urlData )
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:#"%#/%#", documentsDirectory,#"videoName.mp4"];
[urlData writeToFile:filePath atomically:YES];
}
and this code is for playing the video form its directory
NSString *filepath = [NSString stringWithFormat:#"%#/%#", documentsDirectory,#"videoName.mp4"];
//video URL
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController play];
If you have a valid url of the video, Apple provides an API to directly buffer videos with NSURL.
You should hold a reference to the MPMoviePlayerController object from the controller so that ARC doesn't release the object.
#property (nonatomic,strong) MPMoviePlayerController* mc;
Make the URL
NSURL *url = [NSURL URLWithString:#"http://www.example.com/video.mp4"];
Init MPMoviePlayerController with that URL
MPMoviePlayerController *controller = [[MPMoviePlayerController alloc] initWithContentURL:url];
Resize the controller, add it to your view, play it and enjoy the video.
self.mc = controller; // so that ARC doesn't release the controller
controller.view.frame = self.view.bounds;
[self.view addSubview:controller.view];
[controller play]; //Start playing
For more detail you can visit this playing video from a url in ios7
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 trying to use NSData with MPMoviePlayerViewController.
NSData *data = [NSData dataWithBytesNoCopy:mData3->mappedAddress+100398125 length:2313453 freeWhenDone:NO];
NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF16StringEncoding];
NSURL *movieURL = [NSURL fileURLWithPath:dataString];
MPMoviePlayerViewController *moviePlayerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];
[self presentMoviePlayerViewControllerAnimated:moviePlayerViewController];
This leads to the player opening for a second and then being dismissed.
When I access the movie file locally using the URL to the file in the main bundle it plays perfectly.
How does one use NSData to play a video on iOS?
Thanks
There is no way to play a movie directly from an in-memory NSData blob.