<commit_before>//
//  AudioPlayer+Control.swift
//  AudioPlayer
//
//  Created by <NAME> on 29/03/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import CoreMedia
#if os(iOS) || os(tvOS)
    import UIKit
#endif

extension AudioPlayer {
    /**
     Resume the player.
     */
    public func resume() {
        player?.rate = rate
        state = .Playing
    }

    /**
     Pauses the player.
     */
    public func pause() {
        player?.rate = 0
        state = .Paused
    }

    /**
     Plays previous item in the queue or rewind current item.
     */
    public func previous() {
        if hasPrevious {
            currentItem = queue?.previousItem()
        } else {
            seekToTime(0)
        }
    }

    /**
     Plays next item in the queue.
     */
    public func next() {
        if hasNext {
            currentItem = queue?.nextItem()
        }
    }

    /**
     Plays the next item in the queue and if there isn't, the player will stop.
     */
    public func nextOrStop() {
        if hasNext {
            next()
        } else {
            stop()
        }
    }

    /**
     Stops the player and clear the queue.
     */
    public func stop() {
        player?.rate = 0
        player = nil
        currentItem = nil
        queue = nil

        state = .Stopped
    }

    /**
     Seeks to a specific time.

     - parameter time:            The time to seek to.
     - parameter toleranceBefore: The tolerance allowed before time.<commit_msg>`stop` will now only set properties to nil if they aren't<commit_after>//
//  AudioPlayer+Control.swift
//  AudioPlayer
//
//  Created by <NAME> on 29/03/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import CoreMedia
#if os(iOS) || os(tvOS)
    import UIKit
#endif

extension AudioPlayer {
    /**
     Resume the player.
     */
    public func resume() {
        player?.rate = rate
        state = .Playing
    }

    /**
     Pauses the player.
     */
    public func pause() {
        player?.rate = 0
        state = .Paused
    }

    /**
     Plays previous item in the queue or rewind current item.
     */
    public func previous() {
        if hasPrevious {
            currentItem = queue?.previousItem()
        } else {
            seekToTime(0)
        }
    }

    /**
     Plays next item in the queue.
     */
    public func next() {
        if hasNext {
            currentItem = queue?.nextItem()
        }
    }

    /**
     Plays the next item in the queue and if there isn't, the player will stop.
     */
    public func nextOrStop() {
        if hasNext {
            next()
        } else {
            stop()
        }
    }

    /**
     Stops the player and clear the queue.
     */
    public func stop() {
        if let _ = player {
            player?.rate = 0
            player = nil
        }
        if let _ = currentItem {
            currentItem = nil
        }
        if let _ = queue {
            queue = nil
        }

        state = .Stopped
    }

    /**
     Seeks to a specific time.

     - parameter time:            The time to seek to.
     - parameter toleranceBefore: The tolerance allowed before time.
{'fraction_non_alphanumeric': 0.1008827238335435, 'fraction_numerical': 0.00819672131147541, 'mean_word_length': 1.367910447761194, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5541602', 'n_tokens_mistral': 942, 'n_tokens_neox': 893, 'n_words': 296}