From 3c0774fde3ee94b2a2add1d5f4ce462813ceafde Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Wed, 21 Jan 2015 09:57:01 -0800 Subject: [PATCH] Line break after every CSS rule --- js/file.js | 2 ++ js/main-window.js | 11 ++++++--- js/media.js | 4 ++++ js/playlist-window.js | 17 +++++++++---- js/winamp.js | 56 +++++++++++++++++++++++++++++-------------- 5 files changed, 64 insertions(+), 26 deletions(-) diff --git a/js/file.js b/js/file.js index fa567858..fda7e810 100644 --- a/js/file.js +++ b/js/file.js @@ -2,12 +2,14 @@ // `File` is already a builtin, so we use `MyFile` MyFile = function(){ this.reader = new FileReader(); + this.name = ''; this.url = null; this.fileReference = null; this.setUrl = function(url){ this.url = url; }; this.setFileReference = function(fileReference){ + this.name = fileReference.name; this.fileReference = fileReference; }; this.processBuffer = function(bufferHandler) { diff --git a/js/main-window.js b/js/main-window.js index 296a5f5f..5718bffc 100644 --- a/js/main-window.js +++ b/js/main-window.js @@ -390,9 +390,14 @@ MainWindow = { drop: function(e) { e.stopPropagation(); e.preventDefault(); - var dt = e.dataTransfer; - var file = dt.files[0]; - this.winamp.loadFromFileReference(file); + this.winamp.emptyPlaylist(); + var files = e.dataTransfer.files; + for(var i = 0; i < files.length; i++) { + var file = new MyFile(); + file.setFileReference(files[i]); + this.winamp.enqueue(file); + } + this.winamp.play(); }, _timeString: function(time) { diff --git a/js/media.js b/js/media.js index 2678166e..8d089500 100644 --- a/js/media.js +++ b/js/media.js @@ -156,6 +156,10 @@ Media = { this._position = 0; }, + isEmpty: function() { + return !!this._buffer; + }, + _silence: function() { if(this._source) { this._source.stop(0); diff --git a/js/playlist-window.js b/js/playlist-window.js index a1d57172..4dd9991a 100644 --- a/js/playlist-window.js +++ b/js/playlist-window.js @@ -68,9 +68,13 @@ PlaylistWindow = { tracks.removeChild(tracks.firstChild); } - for(i = 0; i < this.winamp.playlist.length; i++) { + var self = this; + for(var i = 0; i < this.winamp.playlist.length; i++) { var li = document.createElement('li'); li.innerHTML = (i+1) + ". " + this.winamp.playlist[i].name; + li.onclick = (function(trackNumber) { + return function() { self.winamp.playTrack(trackNumber); }; + })(i); tracks.appendChild(li); } @@ -79,7 +83,7 @@ PlaylistWindow = { updateCurrentTrack: function() { var tracks = this.nodes.tracks.children; - for(i = 0; i < tracks.length; i++) { + for(var i = 0; i < tracks.length; i++) { if(i == this.winamp.currentTrack) { tracks[i].classList.add('current'); } else { @@ -101,9 +105,12 @@ PlaylistWindow = { drop: function(e) { e.stopPropagation(); e.preventDefault(); - var dt = e.dataTransfer; - var file = dt.files[0]; - this.winamp.enqueueFromFileReference(file, 0); + var files = e.dataTransfer.files; + for(var i = 0; i < files.length; i++) { + var file = new MyFile(); + file.setFileReference(files[i]); + this.winamp.enqueue(file); + } } } diff --git a/js/winamp.js b/js/winamp.js index c864f064..d44a4b2b 100755 --- a/js/winamp.js +++ b/js/winamp.js @@ -39,7 +39,7 @@ Winamp = { this.setVolume(options.volume); this.setBalance(options.balance); - this.loadFromUrl(options.mediaFile.url, options.mediaFile.name); + this.enqueueFromUrl(options.mediaFile.url, options.mediaFile.name); var skinFile = new MyFile(); skinFile.setUrl(options.skinUrl); this.setSkin(skinFile); @@ -81,7 +81,14 @@ Winamp = { }); this.fileInput.onchange = function(e){ - self.loadFromFileReference(e.target.files[0]); + self.emptyPlaylist(); + var files = e.dataTransfer.files; + for(var i = 0; i < files.length; i++) { + var file = new MyFile(); + file.setFileReference(files[i]); + this.enqueue(file); + } + this.next(); }; }, @@ -131,7 +138,7 @@ Winamp = { if(this.currentTrack > 0) { this.currentTrack = this.currentTrack - 1; window.dispatchEvent(this.events.currentTrackChanged); - this.playFromFileReference(this.playlist[this.currentTrack]); + this.playTrack(this.currentTrack); } }, @@ -165,7 +172,7 @@ Winamp = { this.currentTrack = 0; } window.dispatchEvent(this.events.currentTrackChanged); - this.playFromFileReference(this.playlist[this.currentTrack]); + this.playTrack(this.currentTrack); }, // From 0-100 @@ -242,36 +249,49 @@ Winamp = { this.fileInput.click(); }, - loadFromFileReference: function(fileReference) { + enqueueFromFileReference: function(fileReference) { var file = new MyFile(); file.setFileReference(fileReference); if(new RegExp("(wsz|zip)$", 'i').test(fileReference.name)) { this.skin.setSkinByFile(file); } else { - this.playlist = []; - this.enqueueFromFileReference(fileReference); - this.currentTrack = 0; - this.playFromFileReference(this.playlist[0]); + this.enqueue(file); } }, - playFromFileReference: function(fileReference) { - this.media.autoPlay = true; - this.fileName = fileReference.name; - this.fileManager.bufferFromFileReference(fileReference, this._loadBuffer.bind(this)); + loadFile: function(file) { + this.fileName = file.name; + file.processBuffer(this._loadBuffer.bind(this)); }, - enqueueFromFileReference: function(fileReference, position) { - this.playlist.push(fileReference); + playTrack: function(track) { + this.currentTrack = track; + window.dispatchEvent(this.events.currentTrackChanged); + var file = this.playlist[this.currentTrack]; + this.media.autoPlay = true; + this.loadFile(file); + }, + + enqueue: function(file) { + this.playlist.push(file); + if(this.playlist.length === 1) { + this.loadFile(file); + } + window.dispatchEvent(this.events.tracksUpdated); + }, + + emptyPlaylist: function() { + this.playlist = []; + this.currentTrack = 0; window.dispatchEvent(this.events.tracksUpdated); }, // Used only for the initial load, since it must have a CORS header - loadFromUrl: function(url, fileName) { - this.fileName = fileName; + enqueueFromUrl: function(url, fileName) { var file = new MyFile(); file.setUrl(url); - file.processBuffer(this._loadBuffer.bind(this)); + file.name = fileName; + this.enqueue(file); }, setSkin: function(file) {