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?
But whenever you stream the video, it actually takes up storage in your iPhone. Everytime a video is being watched, your available storage capacity in your phone keeps on getting decreased quite significantly.
1 viewer watching your live stream for 1 hour = 1 viewer hour = 0.64 GB (0.00064 TB) of streaming. 100 viewers watch your live stream for 1 hour each = 100 viewer hours = 64.37 GB (0.06437 TB) of streaming. 1,000 viewers watch your stream for 1 hour each = 1,000 viewer hours = 643.73 GB (0.64373 TB) of streaming.
Not quite sure here how you get your stream but look in to the AVAssetWriter, AVAssetWriterInput and AVAssetWriterPixelBufferAdaptor and as soon as you receive data you should be able to append the data to the to the pixel buffer adaptor using:
appendPixelBuffer:withPresentationTime:
not sure it will work for you but with some fiddling you should be able to adapt your input to match this method. There are lots of example code for setting up the writer
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With