ios - MPMoviePlayerController can't play local file with error _itemFailedToPlayToEnd -


I have a local iPhone compatible MP4 video (I have changed the video for the iPhone, and I have uploaded Tested for a web server and putting its URL in Mobile Safari, it plays perfectly) that I want to use the MPMoviePlayerController

Here's my code:

  NSString * filePath = [[NSBundle mainBundle] pathForResource: @ "Welcome" type: @ "MP4"]; NSURL * fileURL = [NSURL URLWithString: filePath]; PlayerController = [[MP3 MPV Player Controller Alok] initWithContentURL: fileURL]; PlayerController.movieSourceType = MPMovieSourceTypeFile; PlayerController.backgroundView.backgroundColor = [UIColor whiteColor]; PlayerController.view.translatesAutoresizingMaskIntoConstraints = Yes; PlayerController.scalingMode = MPVsklingModSpeechFile; //[playerController.view setFrame: moviePlayerContainerView.frame]; [PlayerController.viewSet Frame: CGRactMake (0, 0, 200, 200)]; [See MoviePlayer ContributorAubview: Player Controller.View]; PlayerController.contentURL = fileURL; PlayerController.fullscreen = Yes; [For player controller preparation]; [Player controller game];   

file URL indicates a valid file:

  (lldb) fileURL / var / mobile / applications / 73C97CC9-731E-4446-A53C-2A8CA30A2393 / Tanisalim.app / Welcome.mp4 (lldb) p (bool) [[NSFileManager defaultManager] fileExistsAtPath: filePath isDirectory: NO] (bool) $ 0 = yes   

When I try to run simulator (both 6.1 and 7.1), it displays a black screen in the frame (if there is a fullscreen not ) or a movie player opens the view controller Is and remains forever "Loading ...". When I run on the device (iOS 7.1), the behavior is similar, but I'm getting this error on the console:

  _itemFailedToPlayToEnd: {kind = 1; New = 2; Old = 0; }   

When I try to directly stream the same video file from the web, it works perfectly:

  // playerController .contentURL = fileURL; PlayerController.contentURL = [NSURL URLWithString: @ "http://mywebsite.com/Welcome.mp4"];   

I have tried different video files but the result is the same. What am i doing wrong

I had the same problem, but it was multi-layered in me case.

  • Make sure that you are using -fileURLthethath: no more -URLWithString: to create your own URL, as opposed to @tagya 22 has been mentioned. It seems that many people have a job, but I was already using a file URL, so something was missing.
  • Make sure that your local file extension (".mp4" is, for example). MPMoviePlayerController A solution that does not like files without extension If you need to store files without any extensions, then create a temporary symlink for the actual file and instead of the "real" file that symlink Give file code to MPMoviePlayerController .
  • Your symlink should be located somewhere in the iOS cache directory (~ / library / cache), otherwise it will not work. I was trying to run a MPMoviePlayerController that was in the temporary directory and that worked on the simulator, but no on my device

    Creating a symlink in the actual video file
      NSError * error; NSFileManager * manager = [NSFileManager defaultManager]; [Manager creates symbolic link at url: linkpath with distinction URL: realfile path error: & amp; Error];    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -