iphone - How can i play video (By Name) from document directory ? -


in application store video in document directory name 'video2.mov' , want play it.

here problem not able video (name 'video2.mov') document directory.

my code :

-(void)playvideo:(nstimer *)thetimer {     nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes);     nsstring *documentsdirectory = [paths objectatindex:0];      nsstring *filepath = [documentsdirectory stringbyappendingpathcomponent:@"video2.mov"];     nslog(@"filepath - %@",filepath);      nsstring *content = [nsstring stringwithcontentsoffile:filepath encoding:nsutf8stringencoding error:null];     nslog(@"contentpath - %@",content);      mpmovieplayerviewcontroller *videoplayerview = [[mpmovieplayerviewcontroller alloc] initwithcontenturl:[nsurl urlwithstring:content]];     [[ccdirector shareddirector] presentmovieplayerviewcontrolleranimated:videoplayerview];     [videoplayerview.movieplayer play]; } 

in console, each time got contentpath null, may not able play video.

here, mistake. please give me suggestion on issue.

try this:

- (nsstring*)getdocumentfilepath:(nsstring*)filename {     nslog(@"%@",filename);     // nserror *error;     nsarray *paths = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); //1     nsstring *documentsdirectory = [paths objectatindex:0]; //2     nsstring* file = [[nsstring alloc]initwithformat:@"%@",filename];     nsstring* path = [documentsdirectory stringbyappendingpathcomponent:file];     nsfilemanager *filemanager = [nsfilemanager defaultmanager];      if (![filemanager fileexistsatpath: path]) //4     {         //nsstring *bundle = [[nsbundle mainbundle] pathforresource:filename oftype:@"plist"]; //5          //[filemanager copyitematpath:bundle topath:path error:&error]; //6     }        return path; } 

and file path this:

 nsurl *url = [nsurl fileurlwithpath:[self getdoucmentpath:path]];   mpmovieplayercontroller* themovie=[[mpmovieplayercontroller alloc] initwithcontenturl:ppturl];     themovie.scalingmode=mpmoviescalingmodeaspectfill;      themovie.view.frame = cgrectmake(60, 20, 700, 500);     themovie.view.center = self.view.center;      //[self.view addsubview:themovie.view];      // register playback finished notification.       [[nsnotificationcenter defaultcenter] addobserver:self                                               selector:@selector(onstop)                                                   name:mpmovieplayerplaybackdidfinishnotification                                                 object:themovie];      // movie playback asynchronous, method returns immediately.       [self.view addsubview:themovie.view];     [themovie play]; 

hope helps!!


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -