all files / tests/dummy/app/controllers/audio-files/ simple.js

54.55% Statements 6/11
100% Branches 0/0
25% Functions 1/4
54.55% Lines 6/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                                                                       
import { inject as service } from '@ember/service';
import { on } from '@ember/object/evented';
import Controller from '@ember/controller';
const URL = 'https://raw.githubusercontent.com/mudcube/MIDI.js/master/examples/soundfont/acoustic_grand_piano-mp3/B5.mp3';
 
export default Controller.extend({
  audio: service(),
 
  initAudioFiles: on('init', function() {
    const audio = this.get('audio');
 
    // Db5.mp3 is an mp3 file located in this project's "public" folder
    audio.load('/ember-audio/Db5.mp3').asSound('note-left').then((sound) => {
      // You can pan a note left (any value between -1 and -0.1)
      sound.changePanTo(-0.7);
    });
 
    // This one is loaded from a URL somewhere on the internet
    audio.load(URL).asSound('note-right').then((sound) => {
      // You can pan a note right (any value between 0.1 and 1)
      sound.changePanTo(0.7);
    });
  }),
 
  actions: {
    playNoteLeft() {
      this.get('audio').getSound('note-left').play();
    },
 
    playNoteRight() {
      this.get('audio').getSound('note-right').play();
    },
 
    playBothNotes() {
      const audio = this.get('audio');
      audio.getSound('note-left').play();
      audio.getSound('note-right').play();
    }
  }
});