Skip to content

Commit

Permalink
Added Video Thumbnails Async
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-headspace committed Nov 25, 2018
1 parent 9109e33 commit f0518ea
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Musgravite/Controller/DetailViewController.swift"
timestampString = "564866494.833429"
timestampString = "564868373.942006"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "195"
endingLineNumber = "195"
startingLineNumber = "197"
endingLineNumber = "197"
landmarkName = "getData(_:_:_:)"
landmarkType = "7">
</BreakpointContent>
Expand Down Expand Up @@ -42,11 +42,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Musgravite/Controller/DetailViewController.swift"
timestampString = "564866494.8340271"
timestampString = "564868373.94261"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "196"
endingLineNumber = "196"
startingLineNumber = "198"
endingLineNumber = "198"
landmarkName = "getData(_:_:_:)"
landmarkType = "7">
</BreakpointContent>
Expand Down
30 changes: 26 additions & 4 deletions Musgravite/Controller/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import Alamofire
import SwiftMessages
import WatchConnectivity
import MapKit
import CoreMedia
import AVFoundation

class DetailViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, WCSessionDelegate, MKMapViewDelegate, CLLocationManagerDelegate {
/* WCSessionDelegate */
Expand Down Expand Up @@ -246,19 +248,39 @@ class DetailViewController: UIViewController, UICollectionViewDelegate, UICollec
return cell
}else if collectionView.tag == 2{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "VideoDetailCollectionViewCell", for: indexPath) as! VideoDetailCollectionViewCell
cell.title.text = labInformation!["video"].arrayValue[indexPath.item].stringValue
cell.image.image = UIImage(named: "grad12")
cell.title.text = URL(string: labInformation!["video"].arrayValue[indexPath.item].stringValue)?.lastPathComponent
DispatchQueue.global(qos: .background).async {
let dimage = self.downloadThumbnail(self.labInformation!["video"].arrayValue[indexPath.item].stringValue)
DispatchQueue.main.async {
cell.image.image = dimage
}
}
return cell
} else if collectionView.tag == 3 {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ModelCellView", for: indexPath) as! ModelCollectionViewCell
cell.image.image = UIImage(named: "grad12")
cell.label.text = labInformation!["material"].arrayValue[indexPath.item].stringValue
cell.image.image = UtilityFunctions().getRandomBackground()
cell.label.text = URL(string: labInformation!["material"].arrayValue[indexPath.item].stringValue)?.lastPathComponent
return cell
} else {
return UICollectionViewCell()
}
}

func downloadThumbnail(_ path:String) -> UIImage {
do {
let asset = AVURLAsset(url: URL(string: path)! , options: nil)
let imgGenerator = AVAssetImageGenerator(asset: asset)
imgGenerator.appliesPreferredTrackTransform = true
let cgImage = try imgGenerator.copyCGImage(at: CMTimeMake(value: 0, timescale: 1), actualTime: nil)
let thumbnail = UIImage(cgImage: cgImage)
return thumbnail
} catch let error {
print("*** Error generating thumbnail: \(error.localizedDescription)")
return UIImage()
}
}


func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if collectionView.tag == 1 {
return
Expand Down
5 changes: 3 additions & 2 deletions Musgravite/View/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@
<rect key="frame" x="0.0" y="0.0" width="219" height="101"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="hlJ-SS-sTg">
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="grad13" translatesAutoresizingMaskIntoConstraints="NO" id="hlJ-SS-sTg">
<rect key="frame" x="0.0" y="0.0" width="219" height="101"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Label" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0MR-dT-ETZ">
Expand Down Expand Up @@ -741,7 +741,7 @@
<rect key="frame" x="0.0" y="0.0" width="219" height="168"/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Label" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tP0-aP-iCD">
<rect key="frame" x="20" y="147" width="179" height="21"/>
<rect key="frame" x="20" y="144" width="179" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" red="0.95294117649999999" green="0.96078431369999995" blue="0.96078431369999995" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
Expand Down Expand Up @@ -1569,6 +1569,7 @@
<image name="eyecol-4" width="117" height="40"/>
<image name="eyecol-5" width="117" height="40"/>
<image name="eyecol-6" width="117" height="40"/>
<image name="grad13" width="600" height="500"/>
<image name="grad17" width="600" height="500"/>
<image name="grad19" width="600" height="500"/>
<image name="head-1" width="400" height="400"/>
Expand Down

0 comments on commit f0518ea

Please sign in to comment.