import { Injectable } from '@angular/core';

import { AudioPlayerService } from '../audio-player/audio-player.service';
import { ChartFileImporterService } from '../chart-file/importer/chart-file-importer.service';

@Injectable()
export class FileStoreService {

    private $audioFileName: string;
    private $chartFileName: string;

    constructor(
        private audioPlayer: AudioPlayerService,
        private chartFileImporter: ChartFileImporterService) {
    }

    get audioFileName(): string {
        return this.$audioFileName;
    }

    set audioFile(file: File) {
        if (this.audioPlayer.playing) {
            this.audioPlayer.stop();
        }
        this.$audioFileName = file.name;
        this.audioPlayer.audio = URL.createObjectURL(file);
    }

    get chartFileName(): string {
        return this.$chartFileName;
    }

    set chartFile(file: File) {
        if (this.audioPlayer.playing) {
            this.audioPlayer.stop();
        }
        this.$chartFileName = file.name;
        const reader = new FileReader();
        reader.onload = () => {
            this.chartFileImporter.import(reader.result);
        };
        reader.readAsText(file);
    }
}

import { Injectable } from '@angular/core';

import { AudioPlayerService } from '../audio-player/audio-player.service';
import { ChartFileImporterService } from '../chart-file/importer/chart-file-importer.service';

@Injectable()
export class FileStoreService {

    private $audioFileName: string;
    private $chartFileName: string;

    constructor(
        private audioPlayer: AudioPlayerService,
        private chartFileImporter: ChartFileImporterService) {
    }

    get audioFileName(): string {
        return this.$audioFileName;
    }

    set audioFile(file: File) {
        this.$audioFileName = file.name;
        this.audioPlayer.audio = URL.createObjectURL(file);
    }

    get chartFileName(): string {
        return this.$chartFileName;
    }

    set chartFile(file: File) {
        this.$chartFileName = file.name;
        const reader = new FileReader();
        reader.onload = () => {
            this.chartFileImporter.import(reader.result);
        };
        reader.readAsText(file);
    }
}

--- 
+++ 
@@ -19,6 +19,9 @@
     }
 
     set audioFile(file: File) {
+        if (this.audioPlayer.playing) {
+            this.audioPlayer.stop();
+        }
         this.$audioFileName = file.name;
         this.audioPlayer.audio = URL.createObjectURL(file);
     }
@@ -28,6 +31,9 @@
     }
 
     set chartFile(file: File) {
+        if (this.audioPlayer.playing) {
+            this.audioPlayer.stop();
+        }
         this.$chartFileName = file.name;
         const reader = new FileReader();
         reader.onload = () => {
fix: Stop audio when new files are loaded
