Implementing picking and deleting a song, next song, previous song
This commit is contained in:
parent
b9866ab164
commit
b4d23ca27f
5 changed files with 73 additions and 33 deletions
|
|
@ -6,13 +6,41 @@ export default Em.Component.extend(musicControlMixin, {
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
goToSong: function(index){
|
goToSong: function(index){
|
||||||
var a = new Audio();
|
if(index !== this.get('playQueuePointer')) {
|
||||||
a.src = this.get('playQueue')[index].url;
|
var dancer = this.get('dancer'), audio = new Audio();
|
||||||
this.get('dancer').load(a);
|
audio.src = this.get('playQueue')[index].url;
|
||||||
this.set('playQueuePointer', index);
|
|
||||||
this.send('play');
|
if(dancer.audio) {
|
||||||
|
this.send('clearCurrentAudio');
|
||||||
|
}
|
||||||
|
|
||||||
|
dancer.load(audio);
|
||||||
|
this.setProperties({
|
||||||
|
playQueuePointer: index,
|
||||||
|
timeElapsed: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
this.send('play');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
clearCurrentAudio: function() {
|
||||||
|
var dancer = this.get('dancer');
|
||||||
|
|
||||||
|
dancer.pause();
|
||||||
|
clearInterval(this.get('incrementElapseTimeHandle'));
|
||||||
|
|
||||||
|
this.setProperties({
|
||||||
|
playQueuePointer: -1,
|
||||||
|
timeElapsed: 0,
|
||||||
|
timeTotal: 0,
|
||||||
|
playing: false
|
||||||
|
});
|
||||||
},
|
},
|
||||||
removeAudio: function(index){
|
removeAudio: function(index){
|
||||||
|
if(index === this.get('playQueuePointer')) {
|
||||||
|
this.send('clearCurrentAudio');
|
||||||
|
}
|
||||||
|
|
||||||
this.get('playQueue').removeAt(index);
|
this.get('playQueue').removeAt(index);
|
||||||
|
|
||||||
//if(index === this.get('playQueuePointer')){
|
//if(index === this.get('playQueuePointer')){
|
||||||
|
|
@ -32,30 +60,31 @@ export default Em.Component.extend(musicControlMixin, {
|
||||||
playerAreaPlay: function(){
|
playerAreaPlay: function(){
|
||||||
if(Em.isEmpty(Em.$('#playerControls:hover'))){
|
if(Em.isEmpty(Em.$('#playerControls:hover'))){
|
||||||
this.send('play');
|
this.send('play');
|
||||||
|
Em.$('#playerArea').removeClass('material-icons').prop('offsetWidth', Em.$('#playerArea').prop('offsetWidth')).addClass('material-icons');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
play: function () {
|
play: function () {
|
||||||
var dancer = this.get('dancer'),
|
var dancer = this.get('dancer'),
|
||||||
playQueue = this.get('playQueue');
|
playQueue = this.get('playQueue');
|
||||||
|
|
||||||
if (this.get('playing')) {
|
if(this.get('playQueuePointer') !== -1 ) {
|
||||||
dancer.pause();
|
if (this.get('playing')) {
|
||||||
clearInterval(this.get('incrementElapseTimeHandle'));
|
dancer.pause();
|
||||||
this.toggleProperty('playing');
|
clearInterval(this.get('incrementElapseTimeHandle'));
|
||||||
this.set('timeElapsed', Math.floor(dancer.getTime()));
|
this.toggleProperty('playing');
|
||||||
} else if(playQueue.length > 0) {
|
this.set('timeElapsed', Math.floor(dancer.getTime()));
|
||||||
if(this.get('volumeMuted')) {
|
|
||||||
dancer.setVolume(0);
|
|
||||||
} else {
|
} else {
|
||||||
dancer.setVolume(this.get('volume')/100);
|
if(this.get('volumeMuted')) {
|
||||||
|
dancer.setVolume(0);
|
||||||
|
} else {
|
||||||
|
dancer.setVolume(this.get('volume')/100);
|
||||||
|
}
|
||||||
|
|
||||||
|
dancer.play();
|
||||||
|
this.set('incrementElapseTimeHandle', window.setInterval(this.incrementElapseTime.bind(this), 1000));
|
||||||
|
this.toggleProperty('playing');
|
||||||
}
|
}
|
||||||
|
|
||||||
dancer.play();
|
|
||||||
this.set('incrementElapseTimeHandle', window.setInterval(this.incrementElapseTime.bind(this), 1000));
|
|
||||||
this.toggleProperty('playing');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Em.$('#playerArea').removeClass('material-icons').prop('offsetWidth', Em.$('#playerArea').prop('offsetWidth')).addClass('material-icons');
|
|
||||||
},
|
},
|
||||||
volumeChanged: function (value) {
|
volumeChanged: function (value) {
|
||||||
this.changePlayerControl('volume', value);
|
this.changePlayerControl('volume', value);
|
||||||
|
|
@ -64,10 +93,24 @@ export default Em.Component.extend(musicControlMixin, {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
next: function () {
|
next: function () {
|
||||||
|
var playQueuePointer = this.get('playQueuePointer'), playQueueLength = this.get('playQueue.length');
|
||||||
|
var nextSong = (playQueuePointer + 1) % playQueueLength;
|
||||||
|
|
||||||
|
this.send('goToSong', nextSong);
|
||||||
},
|
},
|
||||||
previous: function () {
|
previous: function () {
|
||||||
|
if(this.get('timeElapsed') > 5) {
|
||||||
|
this.send('seekChanged', 0);
|
||||||
|
} else {
|
||||||
|
var nextSong = this.get('playQueuePointer');
|
||||||
|
nextSong--;
|
||||||
|
|
||||||
|
if(nextSong < 0) {
|
||||||
|
nextSong = this.get('playQueue.length') - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.send('goToSong', nextSong);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
fullscreen: function () {
|
fullscreen: function () {
|
||||||
|
|
||||||
|
|
@ -111,9 +154,7 @@ export default Em.Component.extend(musicControlMixin, {
|
||||||
Em.$('#fileInput').click();
|
Em.$('#fileInput').click();
|
||||||
},
|
},
|
||||||
playListAreaAddAudio: function(){
|
playListAreaAddAudio: function(){
|
||||||
if(this.get('playQueue').length === 0){
|
this.send('addAudio');
|
||||||
this.send('addAudio');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
speakerViewedChanged: function(value){
|
speakerViewedChanged: function(value){
|
||||||
this.set('speakerViewed', value);
|
this.set('speakerViewed', value);
|
||||||
|
|
@ -191,7 +232,7 @@ export default Em.Component.extend(musicControlMixin, {
|
||||||
kick.on();
|
kick.on();
|
||||||
|
|
||||||
dancer.bind('loaded', function(){
|
dancer.bind('loaded', function(){
|
||||||
self.set('timeTotal', dancer.audio.duration);
|
self.set('timeTotal', Math.round(dancer.audio.duration));
|
||||||
});
|
});
|
||||||
|
|
||||||
window.dancer = dancer;
|
window.dancer = dancer;
|
||||||
|
|
@ -229,7 +270,7 @@ export default Em.Component.extend(musicControlMixin, {
|
||||||
self.notifyPropertyChange('playQueue');
|
self.notifyPropertyChange('playQueue');
|
||||||
|
|
||||||
// make sure to init the first song
|
// make sure to init the first song
|
||||||
if(playQueue.length > 0 && !self.get('dancer').isLoaded()){
|
if(playQueue.length > 0 && self.get('playQueuePointer') === -1){
|
||||||
self.send('goToSong', 0);
|
self.send('goToSong', 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -51,15 +51,15 @@ export default Em.Mixin.create({
|
||||||
decay: 0.02,
|
decay: 0.02,
|
||||||
frequency: [0,5],
|
frequency: [0,5],
|
||||||
|
|
||||||
playQueuePointer: 0,
|
playQueuePointer: -1,
|
||||||
playQueue: Em.A(),
|
playQueue: Em.A(),
|
||||||
beatHistory: Em.A(),
|
beatHistory: Em.A(),
|
||||||
maxBeatHistorySize: 30,
|
maxBeatHistorySize: 30,
|
||||||
timeElapsed: 0,
|
timeElapsed: 0,
|
||||||
timeTotal: 0,
|
timeTotal: 0,
|
||||||
|
|
||||||
playQueueEmpty: Ember.computed.empty('playQueue'),
|
playQueueEmpty: Em.computed.empty('playQueue'),
|
||||||
playQueueNotEmpty: Ember.computed.notEmpty('playQueue'),
|
playQueueNotEmpty: Em.computed.notEmpty('playQueue'),
|
||||||
playQueueMultiple: function(){
|
playQueueMultiple: function(){
|
||||||
return this.get('playQueue.length') > 1;
|
return this.get('playQueue.length') > 1;
|
||||||
}.property('playQueue'),
|
}.property('playQueue'),
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ body {
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
bottom: 0;
|
bottom: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: $footerHeight;
|
height: $footerHeight;
|
||||||
|
|
|
||||||
|
|
@ -42,14 +42,14 @@
|
||||||
class="pull-right" {{action "addAudio"}}>{{paper-icon icon="add" class="playerControllIcon" }}</span>
|
class="pull-right" {{action "addAudio"}}>{{paper-icon icon="add" class="playerControllIcon" }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="playListArea" class={{if playQueueEmpty "cursorPointer"}} {{action "playListAreaAddAudio"}}>
|
<div id="playListArea" class="cursorPointer" {{action "playListAreaAddAudio"}}>
|
||||||
{{#if playQueueEmpty}}
|
{{#if playQueueEmpty}}
|
||||||
<div id="dragHere">Drag your music files here</div>
|
<div id="dragHere">Drag your music files here</div>
|
||||||
{{paper-icon icon="library-music"}}
|
{{paper-icon icon="library-music"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#each playQueue as |item index|}}
|
{{#each playQueue as |item index|}}
|
||||||
<div class="playlistItem cursorPointer {{if (eq index playQueuePointer) "active"}}" {{action "goToSong" index}}>
|
<div class="playlistItem cursorPointer {{if (eq index playQueuePointer) "active"}}" {{action "goToSong" index bubbles=false}}>
|
||||||
{{#if item.title}}
|
{{#if item.title}}
|
||||||
{{item.title}}
|
{{item.title}}
|
||||||
<div class="songArtist">{{item.artist}}</div>
|
<div class="songArtist">{{item.artist}}</div>
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"ember": "~2.0.2",
|
"ember": "~2.0.2",
|
||||||
"ember-qunit": "0.4.9",
|
"jquery": "~2.1.4"
|
||||||
"jquery": "~2.1.4",
|
|
||||||
"qunit": "~1.18.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue