Skip to content

Instantly share code, notes, and snippets.

Avatar

Joey Bodnar JoeyBodnar

  • Bangkok, Thailand
View GitHub Profile
@JoeyBodnar
JoeyBodnar / User.swift
Created September 3, 2017 23:05
Http Auth tutorial, user.swift
View User.swift
import AuthProvider
import FluentProvider
import HTTP
import Vapor
extension User: ResponseRepresentable {}
extension User: Timestampable {}
final class User: Model {
let storage = Storage()
View Pet.swift
import Vapor
import FluentProvider
import HTTP
final class Pet: Model {
let storage = Storage()
var name: String
static let idKey = "id"
static let nameKey = "name"
View User.swift
import Vapor
import FluentProvider
import HTTP
final class User: Model {
let storage = Storage()
var name: String
static let idKey = "id"
static let nameKey = "name"
View UsersController.swift
import Foundation
import Vapor
import HTTP
import AuthProvider
import JWT
final class ExampleUsersController {
private let droplet: Droplet
init(droplet: Droplet) {
View UserModel.swift
extension ExampleUser: ResponseRepresentable {}
extension ExampleUser: Timestampable {}
final class ExampleUser: Model, PasswordAuthenticatable {
let storage = Storage()
public static let hasher = BCryptHasher(cost: 10)
static let nameKey = "email" // Vapor expects this to be set to email, even though it is the username
static let passwordKey = "password"
static let confirmPasswordKey = "confirmPassword"
View gist:475bd7a6e29552f183faa79eecf7b1f3
PART 1
So basically, for me the trick to getting this done is to move the video playing outside the cell, meaning outside cellForRowAtIndexPath. For my video, i had it auto play once the table view stopped scrolling, but if you want it to auto play while scrolling, I think that is possible as well, and I'll discuss how a little later. But first some code.
For the time being, I will assume the videos are not coming from a server (in my case they did, and I can cover that too if you want, just you didn't specify in the beginning so I won't immediately get complicated).
First, you will need a preview image--an image of the first frame of the video. This will be set in cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
VideoCell *cell = (VideoCell *)[[self.tableView dequeueReusableCellWithIdentifier:@"cellReuseId"]]
// asynchronously download and set image:
YourObject *image = self.yourDataSourceArray[indexPath.row].im
View video in table view
Part1.
First, make a file, subclassing NSObject. Call it Download. In the .h file, put this:
@property (strong, nonatomic)NSString *url;
@property BOOL isDownloading;
@property float progress;
@property (strong, nonatomic)NSURLSessionDownloadTask *downloadTask;
Leave the .m file empty.
Now to the view controller. So basically, for me the trick to getting this done is to move the video playing outside the cell, meaning outside cellForRowAtIndexPath. For my video, i had it auto play once the table view stopped scrolling, but if you want it to auto play while scrolling, I think that is possible as well, and I'll discuss how a little later. But first some code.
First, you will need a preview image--an image of the first frame of the video. This will be set in cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath *)indexPath {
@JoeyBodnar
JoeyBodnar / gist:7be323b066058667851b
Created March 28, 2016 05:51
Video Loading/Caching with AVAssetResourceLoader
View gist:7be323b066058667851b
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
VideoCell *videoCell = (VideoCell *)[self.tableView dequeueReusableCellWithIdentifier:@"VideoCell"];
NSString *urlString = @"streaming://download.wavetlan.com/SVV/Media/HTTP/MOV/ConvertedFiles/MediaCoder/MediaCoder_test11_36s_H263_VBR_590kbps_176x144_25fps_MPEG1Layer3_CBR_160kbps_Stereo_22050Hz.mov";
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
// Configure Video Cell Here:
NSURL *url = [NSURL URLWithString:urlString];
videoCell.contentView.backgroundColor = [UIColor clearColor];
videoCell.backgroundColor = [UIColor clearColor];