         }
         assert(self._asset != nil, "Asset should not be nil")
     }
-    
-    func connection(connection: NSURLConnection, didReceiveResponse response: NSURLResponse) {
+
+    func URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveResponse response: NSURLResponse, completionHandler: (NSURLSessionResponseDisposition) -> Void) {
+        debug("Received response")
         self.data = NSMutableData()
         self.response = response
         self.processPendingRequests()
+        completionHandler(.Allow)
     }
-    
-    func connection(connection: NSURLConnection, didReceiveData data: NSData) {
+
+    func URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didReceiveData data: NSData) {
+        debug("Received data")
         self.data?.appendData(data)
         self.processPendingRequests()
     }
-    
-    func connection(connection: NSURLConnection, didFailWithError error: NSError) {
-        print(error)
-    }
-    
-    func connectionDidFinishLoading(connection: NSURLConnection) {
-        self.processPendingRequests()
-        debug("Writing data to local cached file: \(self.cachePath!)")
-        do {
-            try self.data?.writeToFile(self.cachePath!, options: NSDataWritingOptions.AtomicWrite)
-        } catch {
-            debug("Unable to write to original file")
+
+    func URLSession(session: NSURLSession, task: NSURLSessionTask, didCompleteWithError error: NSError?) {
+        if error != nil {
+            debug(error)
+        } else {
+            self.processPendingRequests()
+            debug("Writing data to local cached file: \(self.cachePath!)")
+            do {
+                try self.data?.writeToFile(self.cachePath!, options: NSDataWritingOptions.AtomicWrite)
+            } catch {
+                debug("Unable to write to original file")
+            }
         }
     }
-    
+
     func processPendingRequests() {
         self.pendingRequests = self.pendingRequests.filter { loadingRequest in
             self.fillInContentInformation(loadingRequest.contentInformationRequest)

    return urlComponents?.URL
}

class MediaItem: NSObject, NSURLConnectionDataDelegate, AVAssetResourceLoaderDelegate {
    var pendingRequests = [AVAssetResourceLoadingRequest]()
    var data: NSMutableData?
    var response: NSURLResponse?
    var connection: NSURLConnection?
    
    let mediaURL:  NSURL
    let cachePath: String?

    }
    
    func resourceLoader(resourceLoader: AVAssetResourceLoader, shouldWaitForLoadingOfRequestedResource loadingRequest: AVAssetResourceLoadingRequest) -> Bool {
        if self.connection == nil {
            debug("Starting request to get media URL: \(self.mediaURL)")
            let request = NSURLRequest(URL: replaceUrlScheme(loadingRequest.request.URL!, scheme: "http")!)
            self.connection = session.dataTaskWithRequest(request)
            self.connection?.resume()
        }
        
        self.pendingRequests.append(loadingRequest)
