Discussion Forums  >  Uncategorized

Replies: 13    Views: 296

ianJamesPiano
Code is Art
Profile
Posts: 2661
Reg: Feb 13, 2011
Palm Springs, C...
37,010
09/15/11 10:51 PM (14 years ago)

Caching Video

Hi everyone, wondering if there is a way to let the user cache streaming video files? thanks as always!
 
ianJamesPiano
Code is Art
Profile
Posts: 2661
Reg: Feb 13, 2011
Palm Springs, C...
37,010
like
09/15/11 11:18 PM (14 years ago)
Like how streaming audio gets cached? Thanks Or figure out a way to give user the option to download the streaming video for later offline use? Ps. Congrats on the android code!! Milk and cookies for everyone!!
 
tonycelestino
Aspiring developer
Profile
Posts: 213
Reg: Jun 24, 2011
Maceio
4,080
like
09/16/11 03:37 PM (14 years ago)
I love that idea!
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
09/16/11 05:26 PM (14 years ago)
The hard part is going to be determining the video's lenght. In other words, if it's HUGE the user would never want to wait for the download then watch ( I don't think? ) Maybe a checkbox on the control panel for 'download then play' or 'begin playing from stream' or something? Very hard to stream AND save to phone when it finishes. I'll look into this, great idea.
 
ianJamesPiano
Code is Art
Profile
Posts: 2661
Reg: Feb 13, 2011
Palm Springs, C...
37,010
like
09/16/11 05:34 PM (14 years ago)
Hi Dave, this would be super useful if it could be figured out...working on a language course app with tons of video but want the user to be able to download any of the videos if wants to use offline...having fun with Android by the way, you rock!! FYI , the vid clips would range from 30 seconds to 10min each
 
ianJamesPiano
Code is Art
Profile
Posts: 2661
Reg: Feb 13, 2011
Palm Springs, C...
37,010
like
09/30/11 08:20 PM (14 years ago)
Hi David, just wondering if you had any more thoughts on this, (would solidify a possible client)... I realize u are super busy with Android and other updates so if you think I should nudge this post at a later date that's cool...appreciate everything you and the rest of buzztouch do...thanks! :)
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
10/02/11 08:33 AM (14 years ago)
Hi ian...yes... a little progress but no solution yet. I was working this into the mix while working out the video screens for Android. I'm thinking at this point you'll be best hacking together something on your own for your client to get this to work. Hard to say what the best approach is? Maybe.... a) Copy BT_screen_menuList.m and make your own class file from this. Call it videoList.h, .m b) BT_config.txt points to this as a Custom Plug in screen. c) Custom plug in screen shows a list of videos with thumbnail, title, description. d) Tap row to play video. The 'row tap' method checks if videos is in cache, plays if it is. Else, downloads (shows loading animation), saves, then plays. e) Downloading screen saves video then plays when done. Not sure if you can pull this off or not? BT already does all of this stuff in one way or another but where and how is kinda of scatttered. BT_fileManager will be used to check the cache and save the file. Maybe have a look at the BT_audio.m file to see how that file loads audio from cache or from URL then saves.
 
ianJamesPiano
Code is Art
Profile
Posts: 2661
Reg: Feb 13, 2011
Palm Springs, C...
37,010
like
10/02/11 11:50 AM (14 years ago)
Thanks David, I will work on this and see what I come up with...looking thru the apple developer forums it's kind of a popular question (haven't gotten any response yet tho on the apple dev forums)...I'll report back soon, thanks as always :)
 
ianJamesPiano
Code is Art
Profile
Posts: 2661
Reg: Feb 13, 2011
Palm Springs, C...
37,010
like
10/02/11 09:51 PM (14 years ago)
Hi David, started playing around with ur above suggestions...is there a limit to the file size the app can cache? There is almost 2g of video files, will the user be able to cache all of it if wants to? Video files range from 1mb to 15mb.. Couldn't find definitive answer googling...thanks for your time! Ps. Love to figure this out for other BT members and even create a tutorial if it works out. :)
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
10/02/11 10:26 PM (14 years ago)
iOS does not impose a file-size download limit (today). This means you could fire the downloader to grab any file you want and save it in the app's documents directory. BT_fileManager has a few methods to do this. Using BT_sreen_audio.m as an example... The downloadAudioFile method starts a download. Because the .h file has a remoteConn property (synthesized in the .m file) the downloadAudioFile method initializes the remoteConn property to a new NSURLConnection object. This happens on line 648. Next, because BT_screen_audio implements the NSURLConnection delegate methods it knows what to do when the download is complete. When the download completes, the connectionDidFinishLoading method fires. Back to delegates for a minute. The NSURLConnection is initialized on line 648 it tells iOS that the class file we are in serves as the delegate. It does with with the delgate:self in this: self.remoteConn = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; OK, so this class understands how to handle NSURLConnection methods. These methods are: didReceiveResponse (fires contantly during download, allows you to check how much it's already downloaded) didReceiveData (fires quickly when the download first begins) didFailWithError (fires when something goes wrong) connectionDidFinishLoading (fires when done). So, when the download is complete, another property declared in the .h file is 'full' of data. The receivedData property. This is an instance of an iOS NSMutableData object. So...downloads done, receivedData is 'full' of audo data (any data, could be video, html, pdf, whatever)....we need to save it to the app's documents directory, we call this the cache. This happens here: [BT_fileManager saveDataToFile:receivedData:[self audioFileName]]; connectionDidFinishLoading gets called, we want to save our received data, so we ask the BT_fileManager to save the file and name it audioFileName. You could easily name it anything else. Like: [BT_fileManager saveDataToFile:receivedData:@myvideo.mov]; Back to the original question...if BT_fileManager cannot save a giant file it will print an error to the log. It returns TRUE or FALSE. If we wanted to know if it succeeded or not we could easily have done: if([BT_fileManager saveDataToFile:receivedData:@myvideo.mov]){ //success... }else{ //error, show alert... } The next question is what will happen if you try to load a :60 minute video, that you waited :10 minutes to download, in the native iOS video player? Not sure what will happen with such a large file. May 'stream' it great from the cached file system or it could crap. Not sure. Test this by adding a HUGE video to a project then creating a video screen in your control panel. Point to the massive file and see what happens. iOS won't care if it's loaded from the bundle or the cache, it's still the file system, should behave the same way.
 
ianJamesPiano
Code is Art
Profile
Posts: 2661
Reg: Feb 13, 2011
Palm Springs, C...
37,010
like
10/02/11 10:40 PM (14 years ago)
Ok...so my next question..at what point did u pause to take a breath? Lol...thanks for the info, super appreciated!!
 
David @ buzztouch
buzztouch Evangelist
Profile
Posts: 6866
Reg: Jan 01, 2010
Monterey, CA
78,840
like
10/02/11 11:12 PM (14 years ago)
I have a tall head for all the hats. Get this...took a break to walk out front to figure out what the heck was going on across the street. Some crazy lady was screaming at the top of her lungs over and over again...something was either super-duper bad...or...super duper good going on, wink ;-) I called the police after not being able to get her attention by yelling up (the building has a few tenants on that side of the street) and they arrived in like :05 minutes. They entered CSI style with guns and all after knocking and knocking. Turns out she was all alone having some sort of nightmare! Crazy for sure! I'm sure she's embarrassed to have woken up the entire neighborhood (very quiet around here along the ocean) but we are all happy she's OK. Nuttiest thing ever. Back to Android menu list...still needs improvements....it never ends.
 
ianJamesPiano
Code is Art
Profile
Posts: 2661
Reg: Feb 13, 2011
Palm Springs, C...
37,010
like
10/02/11 11:15 PM (14 years ago)
Dude that's crazy! My sister is a blood spatter expert, talk about stories...glad everything turned out ok..sheesh :)
 
ianJamesPiano
Code is Art
Profile
Posts: 2661
Reg: Feb 13, 2011
Palm Springs, C...
37,010
like
10/03/11 10:07 PM (14 years ago)
Hi David, got these steps underway and getting more familiar with plugins... a) Copy BT_screen_menuList.m and make your own class file from this. Call it videoList.h, .m b) BT_config.txt points to this as a Custom Plug in screen. i did test a 120mb hour long mp4 embedded into the app and seemed to play fine not sure if this post is of any use http://www.cocoabuilder.com/archive/cocoa/304824-caching-streaming-video.html No screaming ladies tonight? :)
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.