Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To download the video from YouTube:</p> <ol> <li>Get the URL to download from, via the YouTube API or whatever other method.</li> <li>Create an <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSOutputStream_Class/Reference/Reference.html" rel="noreferrer">NSOutputStream</a> or <a href="http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSFileHandle_Class/Reference/Reference.html" rel="noreferrer">NSFileHandle</a> opened on a temporary file (in <code>NSTemporaryDirectory()</code> or a temp-named file in your Documents directory).</li> <li>Set up your progress bar and whatever else you need to do.</li> <li>Allocate and start an NSURLConnection to fetch the file from the URL. Do not use <code>sendSynchronousRequest:returningResponse:error:</code>, of course.</li> <li>In the <code>connection:didReceiveResponse:</code> delegate method, read out the length of data to be downloaded for proper updating of the progress bar.</li> <li>In the <code>connection:didReceiveData:</code> delegate method, write the data to the output stream/file handle and update the progress bar as necessary.</li> <li>In <code>connectionDidFinishLoading:</code> or <code>connection:didFailWithError:</code>, close the output stream/file handle and rename or delete the temporary file as appropriate.</li> </ol> <p>To play it back, just use NSURL's <code>fileURLWithPath:</code> to create a URL pointing to the local file in the Documents directory and play it as you would any remote video.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload