{"action":"created","comment":{"url":"https://api.github.com/repos/podverse/podverse/pulls/comments/50795251","id":50795251,"diff_hunk":"@@ -0,0 +1,252 @@\n+//\n+//  PVClipStreamer.swift\n+//  podverse\n+//\n+//  Created by Mitchell Downey on 1/23/16.\n+//  Copyright © 2016 Mitchell Downey. All rights reserved.\n+//\n+\n+import UIKit\n+import AVFoundation\n+import MobileCoreServices\n+\n+var playFileContext = \"playFileContext\"\n+\n+// Extension to receive a response from the URL and access response header information like file size via byte range\n+extension NSURL {\n+    var remoteSize: Int64 {\n+        var contentLength: Int64 = NSURLSessionTransferSizeUnknown\n+        let request = NSMutableURLRequest(URL: self, cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 30.0);\n+        request.HTTPMethod = \"HEAD\";\n+        request.timeoutInterval = 5;\n+        let group = dispatch_group_create()\n+        dispatch_group_enter(group)\n+        NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: { (data, response, error) -> Void in\n+            if let httpResponse = response as? NSHTTPURLResponse {\n+                if let contentType = httpResponse.allHeaderFields[\"Content-Length\"] as? String {\n+                    print(contentType)\n+                }\n+            }\n+            contentLength = response?.expectedContentLength ?? NSURLSessionTransferSizeUnknown\n+            dispatch_group_leave(group)\n+        }).resume()\n+        dispatch_group_wait(group, dispatch_time(DISPATCH_TIME_NOW, Int64(5 * NSEC_PER_SEC)))\n+        return contentLength\n+    }\n+}\n+\n+class PVClipStreamer: NSObject, AVAssetResourceLoaderDelegate, NSURLConnectionDataDelegate {\n+    \n+    static let sharedInstance = PVClipStreamer()\n+    \n+    var mediaPlayer: AVPlayer?\n+    var mediaPlayerItems = [AVPlayerItem]()\n+    var isObserving = false\n+    var pendingRequests = [AVAssetResourceLoadingRequest]()\n+    var mediaFileData = NSMutableData()\n+    var response: NSURLResponse?\n+    var connection: NSURLConnection?\n+    \n+    var episodeDuration: Double!\n+\n+    var clipStartTimeInSeconds: Double?\n+    var clipEndTimeInSeconds: Double?\n+    var startBytesRange: Int?\n+    var endBytesRange: Int?\n+    \n+    var metadataBytesOffset = 0\n+\n+    \n+    func streamClip(clip: Clip) {\n+        // Reset the connection to nil before streaming a new clip\n+        self.connection = nil\n+        \n+        if let mediaURLString = clip.episode.mediaURL {\n+            \n+            // Get remote file total bytes\n+            let remoteFileSize = NSURL(string: mediaURLString)!.remoteSize","path":"podverse/PVClipStreamer.swift","position":67,"original_position":67,"commit_id":"464f9ecdf1e51e23ddc6a5a33c8527a47cb2a99d","original_commit_id":"cc27865e69f96230d7f8aa2f60f1f8c050d75263","user":{"login":"kreonjr","id":5912405,"avatar_url":"https://avatars.githubusercontent.com/u/5912405?v=3","gravatar_id":"","url":"https://api.github.com/users/kreonjr","html_url":"https://github.com/kreonjr","followers_url":"https://api.github.com/users/kreonjr/followers","following_url":"https://api.github.com/users/kreonjr/following{/other_user}","gists_url":"https://api.github.com/users/kreonjr/gists{/gist_id}","starred_url":"https://api.github.com/users/kreonjr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kreonjr/subscriptions","organizations_url":"https://api.github.com/users/kreonjr/orgs","repos_url":"https://api.github.com/users/kreonjr/repos","events_url":"https://api.github.com/users/kreonjr/events{/privacy}","received_events_url":"https://api.github.com/users/kreonjr/received_events","type":"User","site_admin":false},"body":"tsk tsk, unwrap please. Or even better use guard to return if the URL is invalid.","created_at":"2016-01-26T04:43:12Z","updated_at":"2016-01-26T04:43:12Z","html_url":"https://github.com/podverse/podverse/pull/114#discussion_r50795251","pull_request_url":"https://api.github.com/repos/podverse/podverse/pulls/114","_links":{"self":{"href":"https://api.github.com/repos/podverse/podverse/pulls/comments/50795251"},"html":{"href":"https://github.com/podverse/podverse/pull/114#discussion_r50795251"},"pull_request":{"href":"https://api.github.com/repos/podverse/podverse/pulls/114"}}},"pull_request":{"url":"https://api.github.com/repos/podverse/podverse/pulls/114","id":57024339,"html_url":"https://github.com/podverse/podverse/pull/114","diff_url":"https://github.com/podverse/podverse/pull/114.diff","patch_url":"https://github.com/podverse/podverse/pull/114.patch","issue_url":"https://api.github.com/repos/podverse/podverse/issues/114","number":114,"state":"open","locked":false,"title":"Refactor media player; Update clip maker; Add clip streaming; UI changes","user":{"login":"mitchdowney","id":2262919,"avatar_url":"https://avatars.githubusercontent.com/u/2262919?v=3","gravatar_id":"","url":"https://api.github.com/users/mitchdowney","html_url":"https://github.com/mitchdowney","followers_url":"https://api.github.com/users/mitchdowney/followers","following_url":"https://api.github.com/users/mitchdowney/following{/other_user}","gists_url":"https://api.github.com/users/mitchdowney/gists{/gist_id}","starred_url":"https://api.github.com/users/mitchdowney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitchdowney/subscriptions","organizations_url":"https://api.github.com/users/mitchdowney/orgs","repos_url":"https://api.github.com/users/mitchdowney/repos","events_url":"https://api.github.com/users/mitchdowney/events{/privacy}","received_events_url":"https://api.github.com/users/mitchdowney/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-01-25T03:01:59Z","updated_at":"2016-01-26T04:43:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"57182c88bd9ee5b6eace1c0353510892628be13b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/podverse/podverse/pulls/114/commits","review_comments_url":"https://api.github.com/repos/podverse/podverse/pulls/114/comments","review_comment_url":"https://api.github.com/repos/podverse/podverse/pulls/comments{/number}","comments_url":"https://api.github.com/repos/podverse/podverse/issues/114/comments","statuses_url":"https://api.github.com/repos/podverse/podverse/statuses/464f9ecdf1e51e23ddc6a5a33c8527a47cb2a99d","head":{"label":"podverse:streamClip","ref":"streamClip","sha":"464f9ecdf1e51e23ddc6a5a33c8527a47cb2a99d","user":{"login":"podverse","id":11860029,"avatar_url":"https://avatars.githubusercontent.com/u/11860029?v=3","gravatar_id":"","url":"https://api.github.com/users/podverse","html_url":"https://github.com/podverse","followers_url":"https://api.github.com/users/podverse/followers","following_url":"https://api.github.com/users/podverse/following{/other_user}","gists_url":"https://api.github.com/users/podverse/gists{/gist_id}","starred_url":"https://api.github.com/users/podverse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/podverse/subscriptions","organizations_url":"https://api.github.com/users/podverse/orgs","repos_url":"https://api.github.com/users/podverse/repos","events_url":"https://api.github.com/users/podverse/events{/privacy}","received_events_url":"https://api.github.com/users/podverse/received_events","type":"Organization","site_admin":false},"repo":{"id":33634509,"name":"podverse","full_name":"podverse/podverse","owner":{"login":"podverse","id":11860029,"avatar_url":"https://avatars.githubusercontent.com/u/11860029?v=3","gravatar_id":"","url":"https://api.github.com/users/podverse","html_url":"https://github.com/podverse","followers_url":"https://api.github.com/users/podverse/followers","following_url":"https://api.github.com/users/podverse/following{/other_user}","gists_url":"https://api.github.com/users/podverse/gists{/gist_id}","starred_url":"https://api.github.com/users/podverse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/podverse/subscriptions","organizations_url":"https://api.github.com/users/podverse/orgs","repos_url":"https://api.github.com/users/podverse/repos","events_url":"https://api.github.com/users/podverse/events{/privacy}","received_events_url":"https://api.github.com/users/podverse/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/podverse/podverse","description":"Podcast subscribing and clip sharing mobile app","fork":false,"url":"https://api.github.com/repos/podverse/podverse","forks_url":"https://api.github.com/repos/podverse/podverse/forks","keys_url":"https://api.github.com/repos/podverse/podverse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/podverse/podverse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/podverse/podverse/teams","hooks_url":"https://api.github.com/repos/podverse/podverse/hooks","issue_events_url":"https://api.github.com/repos/podverse/podverse/issues/events{/number}","events_url":"https://api.github.com/repos/podverse/podverse/events","assignees_url":"https://api.github.com/repos/podverse/podverse/assignees{/user}","branches_url":"https://api.github.com/repos/podverse/podverse/branches{/branch}","tags_url":"https://api.github.com/repos/podverse/podverse/tags","blobs_url":"https://api.github.com/repos/podverse/podverse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/podverse/podverse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/podverse/podverse/git/refs{/sha}","trees_url":"https://api.github.com/repos/podverse/podverse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/podverse/podverse/statuses/{sha}","languages_url":"https://api.github.com/repos/podverse/podverse/languages","stargazers_url":"https://api.github.com/repos/podverse/podverse/stargazers","contributors_url":"https://api.github.com/repos/podverse/podverse/contributors","subscribers_url":"https://api.github.com/repos/podverse/podverse/subscribers","subscription_url":"https://api.github.com/repos/podverse/podverse/subscription","commits_url":"https://api.github.com/repos/podverse/podverse/commits{/sha}","git_commits_url":"https://api.github.com/repos/podverse/podverse/git/commits{/sha}","comments_url":"https://api.github.com/repos/podverse/podverse/comments{/number}","issue_comment_url":"https://api.github.com/repos/podverse/podverse/issues/comments{/number}","contents_url":"https://api.github.com/repos/podverse/podverse/contents/{+path}","compare_url":"https://api.github.com/repos/podverse/podverse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/podverse/podverse/merges","archive_url":"https://api.github.com/repos/podverse/podverse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/podverse/podverse/downloads","issues_url":"https://api.github.com/repos/podverse/podverse/issues{/number}","pulls_url":"https://api.github.com/repos/podverse/podverse/pulls{/number}","milestones_url":"https://api.github.com/repos/podverse/podverse/milestones{/number}","notifications_url":"https://api.github.com/repos/podverse/podverse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/podverse/podverse/labels{/name}","releases_url":"https://api.github.com/repos/podverse/podverse/releases{/id}","deployments_url":"https://api.github.com/repos/podverse/podverse/deployments","created_at":"2015-04-08T22:00:36Z","updated_at":"2016-01-19T01:09:39Z","pushed_at":"2016-01-26T04:38:56Z","git_url":"git://github.com/podverse/podverse.git","ssh_url":"git@github.com:podverse/podverse.git","clone_url":"https://github.com/podverse/podverse.git","svn_url":"https://github.com/podverse/podverse","homepage":null,"size":27307,"stargazers_count":2,"watchers_count":2,"language":"Swift","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":14,"forks":1,"open_issues":14,"watchers":2,"default_branch":"master"}},"base":{"label":"podverse:master","ref":"master","sha":"dd425abf296474357f95fa0dcdc6fa1b9f04f846","user":{"login":"podverse","id":11860029,"avatar_url":"https://avatars.githubusercontent.com/u/11860029?v=3","gravatar_id":"","url":"https://api.github.com/users/podverse","html_url":"https://github.com/podverse","followers_url":"https://api.github.com/users/podverse/followers","following_url":"https://api.github.com/users/podverse/following{/other_user}","gists_url":"https://api.github.com/users/podverse/gists{/gist_id}","starred_url":"https://api.github.com/users/podverse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/podverse/subscriptions","organizations_url":"https://api.github.com/users/podverse/orgs","repos_url":"https://api.github.com/users/podverse/repos","events_url":"https://api.github.com/users/podverse/events{/privacy}","received_events_url":"https://api.github.com/users/podverse/received_events","type":"Organization","site_admin":false},"repo":{"id":33634509,"name":"podverse","full_name":"podverse/podverse","owner":{"login":"podverse","id":11860029,"avatar_url":"https://avatars.githubusercontent.com/u/11860029?v=3","gravatar_id":"","url":"https://api.github.com/users/podverse","html_url":"https://github.com/podverse","followers_url":"https://api.github.com/users/podverse/followers","following_url":"https://api.github.com/users/podverse/following{/other_user}","gists_url":"https://api.github.com/users/podverse/gists{/gist_id}","starred_url":"https://api.github.com/users/podverse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/podverse/subscriptions","organizations_url":"https://api.github.com/users/podverse/orgs","repos_url":"https://api.github.com/users/podverse/repos","events_url":"https://api.github.com/users/podverse/events{/privacy}","received_events_url":"https://api.github.com/users/podverse/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/podverse/podverse","description":"Podcast subscribing and clip sharing mobile app","fork":false,"url":"https://api.github.com/repos/podverse/podverse","forks_url":"https://api.github.com/repos/podverse/podverse/forks","keys_url":"https://api.github.com/repos/podverse/podverse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/podverse/podverse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/podverse/podverse/teams","hooks_url":"https://api.github.com/repos/podverse/podverse/hooks","issue_events_url":"https://api.github.com/repos/podverse/podverse/issues/events{/number}","events_url":"https://api.github.com/repos/podverse/podverse/events","assignees_url":"https://api.github.com/repos/podverse/podverse/assignees{/user}","branches_url":"https://api.github.com/repos/podverse/podverse/branches{/branch}","tags_url":"https://api.github.com/repos/podverse/podverse/tags","blobs_url":"https://api.github.com/repos/podverse/podverse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/podverse/podverse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/podverse/podverse/git/refs{/sha}","trees_url":"https://api.github.com/repos/podverse/podverse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/podverse/podverse/statuses/{sha}","languages_url":"https://api.github.com/repos/podverse/podverse/languages","stargazers_url":"https://api.github.com/repos/podverse/podverse/stargazers","contributors_url":"https://api.github.com/repos/podverse/podverse/contributors","subscribers_url":"https://api.github.com/repos/podverse/podverse/subscribers","subscription_url":"https://api.github.com/repos/podverse/podverse/subscription","commits_url":"https://api.github.com/repos/podverse/podverse/commits{/sha}","git_commits_url":"https://api.github.com/repos/podverse/podverse/git/commits{/sha}","comments_url":"https://api.github.com/repos/podverse/podverse/comments{/number}","issue_comment_url":"https://api.github.com/repos/podverse/podverse/issues/comments{/number}","contents_url":"https://api.github.com/repos/podverse/podverse/contents/{+path}","compare_url":"https://api.github.com/repos/podverse/podverse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/podverse/podverse/merges","archive_url":"https://api.github.com/repos/podverse/podverse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/podverse/podverse/downloads","issues_url":"https://api.github.com/repos/podverse/podverse/issues{/number}","pulls_url":"https://api.github.com/repos/podverse/podverse/pulls{/number}","milestones_url":"https://api.github.com/repos/podverse/podverse/milestones{/number}","notifications_url":"https://api.github.com/repos/podverse/podverse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/podverse/podverse/labels{/name}","releases_url":"https://api.github.com/repos/podverse/podverse/releases{/id}","deployments_url":"https://api.github.com/repos/podverse/podverse/deployments","created_at":"2015-04-08T22:00:36Z","updated_at":"2016-01-19T01:09:39Z","pushed_at":"2016-01-26T04:38:56Z","git_url":"git://github.com/podverse/podverse.git","ssh_url":"git@github.com:podverse/podverse.git","clone_url":"https://github.com/podverse/podverse.git","svn_url":"https://github.com/podverse/podverse","homepage":null,"size":27307,"stargazers_count":2,"watchers_count":2,"language":"Swift","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":14,"forks":1,"open_issues":14,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/podverse/podverse/pulls/114"},"html":{"href":"https://github.com/podverse/podverse/pull/114"},"issue":{"href":"https://api.github.com/repos/podverse/podverse/issues/114"},"comments":{"href":"https://api.github.com/repos/podverse/podverse/issues/114/comments"},"review_comments":{"href":"https://api.github.com/repos/podverse/podverse/pulls/114/comments"},"review_comment":{"href":"https://api.github.com/repos/podverse/podverse/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/podverse/podverse/pulls/114/commits"},"statuses":{"href":"https://api.github.com/repos/podverse/podverse/statuses/464f9ecdf1e51e23ddc6a5a33c8527a47cb2a99d"}}}}