<commit_before>//  Copyright © 2020 <NAME>. All rights reserved.

import MediaPlayer

class SystemMediaPlayer : MediaPlayer {
    private let player = MPMusicPlayerController.systemMusicPlayer
    private var previousTime = -1.0
    private var timer: Timer?
    weak var delegate: MediaPlayerDelegate?

    init(queue: MPMediaItemCollection? = nil, delegate: MediaPlayerDelegate?) {
        self.delegate = delegate
        if let queue = queue {
            player.setQueue(with: queue)
        }
        updateNowPlaying()
        updatePlaybackState()
        // if we're already playing something, then setup the timer
        if case .playing = player.playbackState {
            addPeriodicTimeObserver()
        }
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(updateNowPlaying),
            name: .MPMusicPlayerControllerNowPlayingItemDidChange,
            object: nil)
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(updatePlaybackState),
            name: .MPMusicPlayerControllerPlaybackStateDidChange,
            object: nil)
    }

    func togglePlayback() {
        switch player.playbackState {
        case .playing:
            pause()
        case .paused, .stopped:
            play()
        default:
            break
        }
    }

    func play() {
        addPeriodicTimeObserver()
        player.play()
        updatePlaybackState()
    }
<commit_msg>SystemMediaPlayer should just play if the state is not already playing<commit_after>//  Copyright © 2020 <NAME>. All rights reserved.

import MediaPlayer

class SystemMediaPlayer : MediaPlayer {
    private let player = MPMusicPlayerController.systemMusicPlayer
    private var previousTime = -1.0
    private var timer: Timer?
    weak var delegate: MediaPlayerDelegate?

    init(queue: MPMediaItemCollection? = nil, delegate: MediaPlayerDelegate?) {
        self.delegate = delegate
        if let queue = queue {
            player.setQueue(with: queue)
        }
        updateNowPlaying()
        updatePlaybackState()
        // if we're already playing something, then setup the timer
        if case .playing = player.playbackState {
            addPeriodicTimeObserver()
        }
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(updateNowPlaying),
            name: .MPMusicPlayerControllerNowPlayingItemDidChange,
            object: nil)
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(updatePlaybackState),
            name: .MPMusicPlayerControllerPlaybackStateDidChange,
            object: nil)
    }

    func togglePlayback() {
        switch player.playbackState {
        case .playing:
            pause()
        default:
            play()
        }
    }

    func play() {
        addPeriodicTimeObserver()
        player.play()
        updatePlaybackState()
    }

{'fraction_non_alphanumeric': 0.07399932727884292, 'fraction_numerical': 0.004036326942482341, 'mean_word_length': 2.1272344900105153, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1856459', 'n_tokens_mistral': 760, 'n_tokens_neox': 726, 'n_words': 190}