iOS video streaming and storing on device afterwards

Tudor picture Tudor · Jun 9, 2011 · Viewed 8.6k times · Source

So far I know how to stream a video and how to download it and afterwards stream it, but here's the tricky bit: streaming it once, storing it on the device and in the future play it from the device.

Is that possible?

Answer

Dyldo42 picture Dyldo42 · Jul 12, 2011

It's quite easy to save the video. Do something similar to this:

//Saving Movie
NSMutableData *data = [[NSMutableData alloc] init];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];          
[archiver encodeObject:*MovieObject* forKey:@"MovieObjectDataKey"];
[archiver finishEncoding];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"MovieObjectDefaultsDataKey"];
[archiver release];
[data release];

//Retrieving movie 
NSData *savedMovieData = [[NSUserDefaults standardUserDefaults] objectForKey:@"MovieObjectDefaultsDataKey"];
if (savedMovieData != nil) {
    NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:savedMovieData];
    *MovieObject* = [[unarchiver decodeObjectForKey:@"MovieObjectDataKey"] retain];
    [unarchiver finishDecoding];
    [savedMovieData release];
    [unarchiver release];
} else {
    //Download Stream of Your Movie
}

The only thing you really have to change there is * MovieObject *, once in each step.