<commit_before>﻿using System;
using System.Collections.Generic;
using NAudio.Wave;

namespace MusicPickerDeviceApp.App
{
    public class Player
    {
        private IWavePlayer waveOutDevice { get; set; }
        private Library library;
        public string CurrentSong { get; set; }
        public delegate void NextTrackEvent();

        public Player(Library library)
        {
            waveOutDevice = new WaveOutEvent();
            this.library = library;
            waveOutDevice = new WaveOutEvent();
        }

        public void SetTrack(string trackId)
        {
            this.CurrentSong = trackId;
            Track track = this.library.GetTrack(trackId);
            WaveStream stream = new AudioFileReader(track.Path);
            waveOutDevice.Init(stream);
        }

        public void Play()
        {
            waveOutDevice.Play();
        }

        public void Pause()
        {
            waveOutDevice.Pause();
        }

        public void Stop()
        {
            waveOutDevice.Stop();
        }

        public void AttachNextCallback(NextTrackEvent nextCallback)
        {
            waveOutDevice.PlaybackStopped += (sender, ev) => nextCallback();
        }
    }
}<commit_msg>Playing of unknown track IDs error handling<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using NAudio.Wave;

namespace MusicPickerDeviceApp.App
{
    public class Player
    {
        private IWavePlayer waveOutDevice { get; set; }
        private Library library;
        public string CurrentSong { get; set; }
        public delegate void NextTrackEvent();
        private NextTrackEvent nextCallback;

        public Player(Library library)
        {
            waveOutDevice = new WaveOutEvent();
            this.library = library;
            waveOutDevice = new WaveOutEvent();
        }

        public void SetTrack(string trackId)
        {
            this.CurrentSong = trackId;
            Track track = this.library.GetTrack(trackId);
            if (track != null)
            {
                WaveStream stream = new AudioFileReader(track.Path);
                waveOutDevice.Init(stream);
            }
            else
            {
                nextCallback();
            }
        }

        public void Play()
        {
            try
            {
                waveOutDevice.Play();
            }
            catch
            {
                return;
            }
        }

        public void Pause()
        {
            waveOutDevice.Pause();
        }

        public void Stop()
        {
            waveOutDevice.Stop();
        }

        public void AttachNextCallback(NextTrackEvent nextCallback)
        {
            this.nextCallback = nextCallback;
            waveOutDevice.PlaybackStopped += (sender, ev) => nextCallback();
        }
    }
}
{'fraction_non_alphanumeric': 0.07977606717984605, 'fraction_numerical': 0.0, 'mean_word_length': 1.543594306049822, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6699269', 'n_tokens_mistral': 729, 'n_tokens_neox': 696, 'n_words': 167}