<commit_before>//
//  Player.swift
//  Pods
//
//  Created by <NAME> on 3/7/17.
//
//

import UIKit
import AVKit

/// A player error
public enum PlayerError: Int
{
    case unknown
    case loading
    
    private static let Domain = "com.vimeo.PlayerKit"
    
    /// The associated error
    ///
    /// - Returns: The error
    public func error() -> NSError
    {
        switch self
        {
        case .unknown:
            
            return NSError(domain: type(of: self).Domain, code: self.rawValue, userInfo: [NSLocalizedDescriptionKey: "An unknown error occurred."])
            
        case .loading:
            
            return NSError(domain: type(of: self).Domain, code: self.rawValue, userInfo: [NSLocalizedDescriptionKey: "An error occurred while loading the content."])
        }
    }
}

/// Represents the current state of the player
///
/// - loading: The player is loading or buffering
/// - ready: The player is ready for playback
/// - failed: The player has failed
@objc public enum PlayerState: Int
{
    case loading
    case ready
    case failed
}

/// An object that adopts the PlayerDelegate protocol can receive updates from the player.
@objc public protocol PlayerDelegate: class
{
    func playerDidUpdateState(player: Player, previousState: PlayerState)
    func playerDidUpdatePlaying(player: Player)
    func playerDidUpdateTime(player: Player)
    func playerDidUpdateBufferedTime(player: Player)
}

/// An object that adopts the Player protocol is responsible for implementing the API and calling PlayerDelegate methods where appropriate.
@objc public protocol Player: class
{
    weak var delegate: PlayerDelegate? { get set }
    
    var state: PlayerState { get }
    
    var duration: TimeInterval { get }
    
    var time: TimeInterval { get }
    
    var bufferedTime: TimeInterval { get }
    
    var playing: Bool { get }
    
    var error: NSError? { get }
    
    /// Seeks to the specified time
    ///
    /// - Parameter time: The specified time
    func seek(to time: TimeInterval)
    
    /// Play the video
    func play()
    
    /// Pause the video
    func pause()
}

// MARK: Identity Protocols

/// A player that adopts the ProvidesView protocol is capable of providing a view to be added to a view hierarchy.
@objc public protocol ProvidesView
{
    var view: UIView { get }
}

// MARK: Capability Protocols

/// A player that adopts the ProvidesView protocol is capable of AirPlay playback.
@objc public protocol AirPlayCapable
{
    var isAirPlayEnabled: Bool { get set }
}

/// A player that adopts the ProvidesView protocol is capable of setting audio volume.
@objc public protocol VolumeCapable
{
    var volume: Float { get set }
}

/// A player that adopts the ProvidesView protocol is capable of setting the video fill mode.
@objc public protocol FillModeCapable
{
    var fillMode: FillMode { get set }
}

@objc public enum FillMode: Int
{
    case fit
    case fill
}

/// The metadata that should be attached to any type of text track.
@objc public protocol TextTrackMetadata
{
    var displayName: String { get }
    var locale: Locale? { get }
    var isSDHTrack: Bool { get }
    
    @objc(displayNameWithLocale:) func displayName(with locale: Locale) -> String
}

public func ==(lhs: TextTrackMetadata, rhs: TextTrackMetadata) -> Bool
{
    return (lhs.locale == rhs.locale && lhs.isSDHTrack == rhs.isSDHTrack)
}

/// A player that conforms to the TextTrackCapable protocol is capable of advertising and displaying text tracks.
@objc public protocol TextTrackCapable
{
    var selectedTextTrack: TextTrackMetadata? { get }
    var availableTextTracks: [TextTrackMetadata] { get }
    
    func fetchTextTracks(completion: @escaping ([TextTrackMetadata], TextTrackMetadata?) -> Void)
    func select(_ textTrack: TextTrackMetadata?)
}

#if os(iOS)
/// A player that adopts the ProvidesView protocol is capable of Picture in Picture playback.
@objc public protocol PictureInPictureCapable<commit_msg>Change == operator to matches(_:) method<commit_after>//
//  Player.swift
//  Pods
//
//  Created by <NAME> on 3/7/17.
//
//

import UIKit
import AVKit

/// A player error
public enum PlayerError: Int
{
    case unknown
    case loading
    
    private static let Domain = "com.vimeo.PlayerKit"
    
    /// The associated error
    ///
    /// - Returns: The error
    public func error() -> NSError
    {
        switch self
        {
        case .unknown:
            
            return NSError(domain: type(of: self).Domain, code: self.rawValue, userInfo: [NSLocalizedDescriptionKey: "An unknown error occurred."])
            
        case .loading:
            
            return NSError(domain: type(of: self).Domain, code: self.rawValue, userInfo: [NSLocalizedDescriptionKey: "An error occurred while loading the content."])
        }
    }
}

/// Represents the current state of the player
///
/// - loading: The player is loading or buffering
/// - ready: The player is ready for playback
/// - failed: The player has failed
@objc public enum PlayerState: Int
{
    case loading
    case ready
    case failed
}

/// An object that adopts the PlayerDelegate protocol can receive updates from the player.
@objc public protocol PlayerDelegate: class
{
    func playerDidUpdateState(player: Player, previousState: PlayerState)
    func playerDidUpdatePlaying(player: Player)
    func playerDidUpdateTime(player: Player)
    func playerDidUpdateBufferedTime(player: Player)
}

/// An object that adopts the Player protocol is responsible for implementing the API and calling PlayerDelegate methods where appropriate.
@objc public protocol Player: class
{
    weak var delegate: PlayerDelegate? { get set }
    
    var state: PlayerState { get }
    
    var duration: TimeInterval { get }
    
    var time: TimeInterval { get }
    
    var bufferedTime: TimeInterval { get }
    
    var playing: Bool { get }
    
    var error: NSError? { get }
    
    /// Seeks to the specified time
    ///
    /// - Parameter time: The specified time
    func seek(to time: TimeInterval)
    
    /// Play the video
    func play()
    
    /// Pause the video
    func pause()
}

// MARK: Identity Protocols

/// A player that adopts the ProvidesView protocol is capable of providing a view to be added to a view hierarchy.
@objc public protocol ProvidesView
{
    var view: UIView { get }
}

// MARK: Capability Protocols

/// A player that adopts the ProvidesView protocol is capable of AirPlay playback.
@objc public protocol AirPlayCapable
{
    var isAirPlayEnabled: Bool { get set }
}

/// A player that adopts the ProvidesView protocol is capable of setting audio volume.
@objc public protocol VolumeCapable
{
    var volume: Float { get set }
}

/// A player that adopts the ProvidesView protocol is capable of setting the video fill mode.
@objc public protocol FillModeCapable
{
    var fillMode: FillMode { get set }
}

@objc public enum FillMode: Int
{
    case fit
    case fill
}

/// The metadata that should be attached to any type of text track.
@objc public protocol TextTrackMetadata
{
    var displayName: String { get }
    var locale: Locale? { get }
    var isSDHTrack: Bool { get }
    
    @objc(displayNameWithLocale:) func displayName(with locale: Locale) -> String
}

extension TextTrackMetadata
{
    public func matches(_ other: TextTrackMetadata) -> Bool
    {
        return (self.locale == other.locale && self.isSDHTrack == other.isSDHTrack)
    }
}

/// A player that conforms to the TextTrackCapable protocol is capable of advertising and displaying text tracks.
@objc public protocol TextTrackCapable
{
    var selectedTextTrack: TextTrackMetadata? { get }
    var availableTextTracks: [TextTrackMetadata] { get }
    
    func fetchTextTracks(completion: @escaping ([TextTrackMetadata], TextTrackMetadata?) -> Void)
    func select(_ textTrack: TextTrackMetadata?)
}

#if os(iOS)
/// A player that adopts the ProvidesView protocol is capable of Picture in Picture playback.
@objc public protocol PictureInPictureCapable
{'fraction_non_alphanumeric': 0.08331263968214551, 'fraction_numerical': 0.0009932952570151478, 'mean_word_length': 2.867018722995679, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1981385', 'n_tokens_mistral': 2272, 'n_tokens_neox': 2202, 'n_words': 868}