Created
April 26, 2016 02:32
-
-
Save tamebadger/e7ba3fe359628ceb1f5d169307fb07d5 to your computer and use it in GitHub Desktop.
Audio Player
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Component.extend({ | |
audioPlayer: Ember.inject.service('audio-player'), | |
actions: { | |
start(){ | |
this.get('audioPlayer').start() | |
}, | |
stop(){ | |
this.get('audioPlayer').stop() | |
}, | |
next(){ | |
this.get('audioPlayer').nextSong() | |
}, | |
previous(){ | |
this.get('audioPlayer').previousSong() | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Service.extend({ | |
ids: [0,1,2,3,4,5,6,7,8,9,10], | |
songs: Ember.computed('ids',function(){ | |
return this.get('ids').map(id => { | |
return { id: id, title: `Awesome Song ${id}`} | |
}) | |
}), | |
currentlyPlaying: '', | |
currentIndex: 0, | |
currentStatus: 'stopped', | |
start(){ | |
this.setSongByIndex() | |
this.set('currentStatus','playing') | |
}, | |
stop(){ | |
this.set('currentStatus','stopped') | |
}, | |
nextSong(){ | |
const maxIndex = this.get('ids.length') - 1 | |
const currentIndex = this.get('currentIndex') | |
const nextIndex = currentIndex + 1 | |
if(nextIndex > maxIndex){ | |
this.stop() | |
}else{ | |
this.set('currentIndex',nextIndex) | |
this.setSongByIndex() | |
} | |
}, | |
previousSong(){ | |
const maxIndex = this.get('ids.length') - 1 | |
const currentIndex = this.get('currentIndex') | |
const prevIndex = currentIndex - 1 | |
if(prevIndex < 0){ | |
this.stop() | |
}else{ | |
this.set('currentIndex',prevIndex) | |
this.setSongByIndex() | |
} | |
}, | |
setSongByIndex(){ | |
const songs = this.get('songs') | |
const currentIndex = this.get('currentIndex') | |
this.set('currentlyPlaying',songs[currentIndex]) | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.7.2", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember.debug.js", | |
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js", | |
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment