<commit_before>//
//  DKPhotoPlayerPreviewVC.swift
//  DKPhotoGalleryDemo
//
//  Created by ZhangAo on 15/09/2017.
//  Copyright © 2017 ZhangAo. All rights reserved.
//

import UIKit
import AVKit
import Photos

open class DKPhotoPlayerPreviewVC: DKPhotoBasePreviewVC {

    public var closeBlock: (() -> Void)?
    
    private var playerView: DKPlayerView!
    
    deinit {
        self.playerView.stop()
    }
    
    open override func photoPreviewWillAppear() {
        super.photoPreviewWillAppear()
        
        self.playerView.isControlHidden = true
    }
    
    open override func photoPreviewWillDisappear() {
        super.photoPreviewWillDisappear()
        
        self.playerView.pause()
    }
    
    open override func prepareForReuse() {
        super.prepareForReuse()
        
        self.playerView.reset()
    }
    
    // MARK: - DKPhotoBasePreviewDataSource
    
    open override func createContentView() -> UIView {
        self.playerView = DKPlayerView(controlParentView: self.view)
        return self.playerView
    }
    
    open override func contentSize() -> CGSize {
        return self.view.bounds.size
    }
    
    open override func fetchContent(withProgressBlock progressBlock: @escaping ((Float) -> Void), completeBlock: @escaping ((Any?, Error?) -> Void)) {
        if let videoURL = self.item.videoURL {
            completeBlock(videoURL, nil)
        } else if let asset = self.item.asset {
            let identifier = asset.localIdentifier
            PHImageManager.default().requestAVAsset(forVideo: asset,
                                                    options: nil,
                                                    resultHandler: { [weak self] (avAsset, _, _) in
                                                        if let asset = self?.item.asset, asset.localIdentifier == identifier {
                                                            let URLAsset = avAsset as! AVURLAsset
                                                            completeBlock(URLAsset.url, nil)
                                                        }
            })<commit_msg>Calls completeBlock of requestAVAsset on main thread.<commit_after>//
//  DKPhotoPlayerPreviewVC.swift
//  DKPhotoGalleryDemo
//
//  Created by ZhangAo on 15/09/2017.
//  Copyright © 2017 ZhangAo. All rights reserved.
//

import UIKit
import AVKit
import Photos

open class DKPhotoPlayerPreviewVC: DKPhotoBasePreviewVC {

    public var closeBlock: (() -> Void)?
    
    private var playerView: DKPlayerView!
    
    deinit {
        self.playerView.stop()
    }
    
    open override func photoPreviewWillAppear() {
        super.photoPreviewWillAppear()
        
        self.playerView.isControlHidden = true
    }
    
    open override func photoPreviewWillDisappear() {
        super.photoPreviewWillDisappear()
        
        self.playerView.pause()
    }
    
    open override func prepareForReuse() {
        super.prepareForReuse()
        
        self.playerView.reset()
    }
    
    // MARK: - DKPhotoBasePreviewDataSource
    
    open override func createContentView() -> UIView {
        self.playerView = DKPlayerView(controlParentView: self.view)
        return self.playerView
    }
    
    open override func contentSize() -> CGSize {
        return self.view.bounds.size
    }
    
    open override func fetchContent(withProgressBlock progressBlock: @escaping ((Float) -> Void), completeBlock: @escaping ((Any?, Error?) -> Void)) {
        if let videoURL = self.item.videoURL {
            completeBlock(videoURL, nil)
        } else if let asset = self.item.asset {
            let identifier = asset.localIdentifier
            PHImageManager.default().requestAVAsset(forVideo: asset,
                                                    options: nil,
                                                    resultHandler: { [weak self] (avAsset, _, _) in
                                                        if let asset = self?.item.asset, asset.localIdentifier == identifier {
                                                            DispatchQueue.main.async {
                                                                let URLAsset = avAsset as! AVURLAsset
                                                                completeBlock(URLAsset.url, nil)
                                                            }
                                                        }
            })
{'fraction_non_alphanumeric': 0.07812849787329304, 'fraction_numerical': 0.005372733378106112, 'mean_word_length': 1.4401966138722009, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2403960', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1053, 'n_words': 251}