<commit_before>//
//  VideoWindowController.swift
//  WWDC
//
//  Created by <NAME> on 19/04/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Cocoa
import AVFoundation
import AVKit
import ASCIIwwdc
import ViewUtils

private let _nibName = "VideoWindowController"

class VideoWindowController: NSWindowController {

    var session: Session?
    var event: LiveEvent?
    
    var videoURL: String?
    
    var asset: AVAsset!
    var item: AVPlayerItem!
    
    var transcriptWC: TranscriptWindowController!
    var playerWindow: GRPlayerWindow {
        get {
            return window as! GRPlayerWindow
        }
    }
    var videoNaturalSize = CGSizeZero

    convenience init(session: Session, videoURL: String) {
        self.init(windowNibName: _nibName)
        self.session = session
        self.videoURL = videoURL
    }
    
    convenience init(event: LiveEvent, videoURL: String) {
        self.init(windowNibName: _nibName)
        self.event = event
        self.videoURL = videoURL
        NSNotificationCenter.defaultCenter().addObserverForName(LiveEventTitleAvailableNotification, object: nil, queue: NSOperationQueue.mainQueue()) { note in
            if let title = note.object as? String {
                self.window?.title = "\(title) (Live)"
            }
        }
    }
    
    @IBOutlet weak var playerView: AVPlayerView!
    @IBOutlet weak var progressIndicator: NSProgressIndicator!
    var player: AVPlayer?
    
    override func windowDidLoad() {
        super.windowDidLoad()

        progressIndicator.startAnimation(nil)
        window?.backgroundColor = NSColor.blackColor()

        if let url = NSURL(string: videoURL!) {
            if event == nil {
                player = AVPlayer(URL: url)
                playerView.player = player
                
                // SESSION
                player?.currentItem.asset.loadValuesAsynchronouslyForKeys(["tracks"]) {
                    dispatch_async(dispatch_get_main_queue()) {
                        self.setupWindowSizing()
                        self.setupTimeObserver()
                        
                        if let session = self.session {
                            if session.currentPosition > 0 {
                                self.player?.seekToTime(CMTimeMakeWithSeconds(session.currentPosition, 1))
                            }<commit_msg>Added an argument to disable audio playback during development<commit_after>//
//  VideoWindowController.swift
//  WWDC
//
//  Created by <NAME> on 19/04/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Cocoa
import AVFoundation
import AVKit
import ASCIIwwdc
import ViewUtils

private let _nibName = "VideoWindowController"

class VideoWindowController: NSWindowController {

    var session: Session?
    var event: LiveEvent?
    
    var videoURL: String?
    
    var asset: AVAsset!
    var item: AVPlayerItem!
    
    var transcriptWC: TranscriptWindowController!
    var playerWindow: GRPlayerWindow {
        get {
            return window as! GRPlayerWindow
        }
    }
    var videoNaturalSize = CGSizeZero

    convenience init(session: Session, videoURL: String) {
        self.init(windowNibName: _nibName)
        self.session = session
        self.videoURL = videoURL
    }
    
    convenience init(event: LiveEvent, videoURL: String) {
        self.init(windowNibName: _nibName)
        self.event = event
        self.videoURL = videoURL
        NSNotificationCenter.defaultCenter().addObserverForName(LiveEventTitleAvailableNotification, object: nil, queue: NSOperationQueue.mainQueue()) { note in
            if let title = note.object as? String {
                self.window?.title = "\(title) (Live)"
            }
        }
    }
    
    @IBOutlet weak var playerView: AVPlayerView!
    @IBOutlet weak var progressIndicator: NSProgressIndicator!
    var player: AVPlayer? {
        didSet {
            if let player = player {
                if let args = NSProcessInfo.processInfo().arguments as? [String] {
                    if args.contains("zerovolume") {
                        player.volume = 0
                    }
                }
            }
        }
    }
    
    override func windowDidLoad() {
        super.windowDidLoad()

        progressIndicator.startAnimation(nil)
        window?.backgroundColor = NSColor.blackColor()

        if let url = NSURL(string: videoURL!) {
            if event == nil {
                player = AVPlayer(URL: url)
                playerView.player = player
                
                // SESSION
                player?.currentItem.asset.loadValuesAsynchronouslyForKeys(["tracks"]) {
                    dispatch_async(dispatch_get_main_queue()) {
                        self.setupWindowSizing()
                        self.setupTimeObserver()
                        
                        if let session = self.session {
                            if session.currentPosition > 0 {
                                self.player?.seekToTime(CMTimeMakeWithSeconds(session.currentPosition, 1))
                            }
{'fraction_non_alphanumeric': 0.08006248779535247, 'fraction_numerical': 0.004881859011911736, 'mean_word_length': 1.8471372984991663, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5754648', 'n_tokens_mistral': 1367, 'n_tokens_neox': 1300, 'n_words': 315}