From 8423b0dc2967544e30707394e40347668311d0d4 Mon Sep 17 00:00:00 2001 From: Jordan Eldredge Date: Tue, 4 Nov 2014 21:41:52 -0800 Subject: [PATCH] Allow user to play from url --- winamp.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/winamp.js b/winamp.js index e1a91caa..c296a231 100755 --- a/winamp.js +++ b/winamp.js @@ -81,6 +81,7 @@ function Winamp () { this.media.setVolume(.5); this.nodes = { + 'option': document.getElementById('option'), 'close': document.getElementById('close'), 'shade': document.getElementById('shade'), 'position': document.getElementById('position'), @@ -103,6 +104,15 @@ function Winamp () { 'winamp': document.getElementById('winamp'), }; + this.nodes.option.onclick = function() { + text = "Enter an Internet location to open here:\n"; + text += "For example: http://www.server.com/file.mp3" + file = window.prompt(text, ''); + self.startFile(file, file); + self.media.play(); + self.setStatus('play'); + } + this.nodes.close.onclick = function() { } @@ -151,7 +161,7 @@ function Winamp () { this.nodes.fileInput.onchange = function(e){ var file = e.target.files[0]; - self.loadFileViaReference(file); + self.startFileViaReference(file); } this.nodes.volume.onmousedown = function() { @@ -265,16 +275,20 @@ function Winamp () { e.preventDefault(); var dt = e.dataTransfer; var file = dt.files[0]; - self.loadFileViaReference(file); + self.startFileViaReference(file); } this.nodes.winamp.addEventListener('dragenter', this.dragenter); this.nodes.winamp.addEventListener('dragover', this.dragover); this.nodes.winamp.addEventListener('drop', this.drop); - this.loadFileViaReference = function(fileReference) { + this.startFileViaReference = function(fileReference) { var objectUrl = URL.createObjectURL(fileReference); - self.loadFile(objectUrl, fileReference.name); + self.startFile(objectUrl, fileReference.name); + } + + this.startFile = function(file, fileName) { + self.loadFile(file, fileName); self.media.play(); self.setStatus('play'); }