views:

88

answers:

1

I need to load a video stored in Applications folder in to a table view. When I touched the cell the video plays.

I used the following code to get all the video files in to an array.

    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSArray* contents = [fileManager directoryContentsAtPath:@"/Users/srikanth/Desktop/Projects/UF/Table2/Videos"];
    for(a = 1; a < [contents count]; a++)
        NSLog(@"Array contents: %@", [contents objectAtIndex:a]);
    cells = [[NSMutableArray alloc]initWithCapacity:[contents count]];  

But how can I load the videos into UITableView. I used NSBundle for loading videos by giving path. It worked. But, now I need the videos to load from the array contents. When I touch the cell of the table the corresponding file from the array contents si to be loaded. How can I make it? Thank you.

A: 

Remember, iPhone apps are "sandboxed". Unlike normal apps, they can only see the files in their own directory. In either the simulator or the device, you can't use a directory path that leads to files that are outside the application's directory in the simulator/device.

You're trying to read files from your Mac's desktop and the iPhoneOS will not resolve that path. You've been able to read files in the app's bundle before because those files are in the app's directory.

So, the first thing you need to do is to move the files into the app's directory either in the simulator or the device. With the simulator, the path to the app's directory will be something like:

~/Library/Application Support/iPhone Simulator/3.2/Applications/#app's UUID#/

Put the videos in the documentation folder there.

TechZen
But each time I restart the computer a new #app's UUID#/ is created in the path. So, where should I store the videos ?Thank You .
srikanth rongali
If they are a permanent part of your app, you need to store them in the resource bundle. Otherwise, you will have to move them manually for the simulator directories and on the device you will have to download them with the app itself and save them to the documents folder on the device. It's not supposed to be easy to get files into and out of an apps directory.
TechZen
sorry, It is working. I stored the videos in Documents folder of the application. Thank you.
srikanth rongali