1

The app crashes while trying to fetch data from path/URL (video file stored in documents folder) only for large files (>100 MB).

Device Details: iOS (4.3), iPad 1

  1. URL is perfect (Checked logs)
  2. File exists at that path (checked path)

Note: Crashes on device only.

Below is the code where app crashes:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);

if ([paths count] > 0) 
    {
         filePath = [paths objectAtIndex:0];
         filePath = [filePath stringByAppendingPathComponent:@"Private Documents"];
         filePath = [filePath stringByAppendingPathComponent:@"videos"];
         filePath = [filePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4",st]];
    }

NSURL *fileUrl=[NSURL fileURLWithPath:filePath];
NSMutableData *Data = [NSMutableData dataWithContentsOfURL:fileUrl];  //CRASHES ON THIS LINE
NSLog(@"Data: %d",[Data length]);

Any comments.

James Webster
  • 31,873
  • 11
  • 70
  • 114
Dilip Lilaramani
  • 1,126
  • 13
  • 28

1 Answers1

3

It seems you are running out of memory.

On the device there is normally far less memory available that your simulator and 100MB is a lot to be storing in RAM. Consider breaking the downloadable files into smaller chunks and deal with them in pieces if you can.

I don't think

You are taking to long time and the app gets killed.

as David suggests unless you are doing this on start up.

James Webster
  • 31,873
  • 11
  • 70
  • 114
  • May be you are right but I need to do this, Below are the steps: 1. Read data from file //Crashing 2. Pass data to decrypt this file 3. Then create MP4 file from decrypt data 4. Then pass the URL to MPMoviePlayerControll to play – Dilip Lilaramani Jun 13 '12 at 14:09
  • When I do this in background then i rcv: , Received memory warning. Level=1 , Received memory warning. Level=2 And then crash – Dilip Lilaramani Jun 13 '12 at 15:38
  • 1
    That confirms your problem is a memory issue, rather than a hanging issue. – James Webster Jun 13 '12 at 15:39
  • I checked calling only the method of fetching data from filepath and no other UI & all. still rcv memory warnings & then crashed. – Dilip Lilaramani Jun 13 '12 at 16:49
  • Then quite simply, you can't. The amount of information you want to store in memory is just too much! – James Webster Jun 13 '12 at 16:49
  • Then can you suggest me than how can I play large video files? – Dilip Lilaramani Jun 14 '12 at 07:11
  • Break the video into smaller parts? Find a format which doesn't take up so much space in RAM (A smaller file format doesn't always mean smaller in RAM because it is uncompressed before mapping, indeed a format that is larger on disk might be smaller in memory.) – James Webster Jun 14 '12 at 07:41