| | |
| | | //var katUrl; |
| | | //var selTitel; |
| | | var katName; |
| | | var playingIndex; |
| | | var audioCtx; |
| | | var playState; // 'pause' oder 'play' oder 'stop' |
| | | var audioElem; |
| | | var playingList; |
| | | |
| | | this.init = function () { |
| | | self.mediaPfad = '/'; |
| | |
| | | |
| | | self.fusszeile_umschalten(); |
| | | self.seitenleiste_umschalten(); |
| | | self.dialog_unten_zeigen(); |
| | | self.dialog_unten_zeigen(); |
| | | }; |
| | | |
| | | /* ---------------- Entitaets-Listen ----------------- */ |
| | |
| | | }; |
| | | |
| | | this.kommando = function(kommando) { |
| | | var abs = document.querySelector('#abspieler').value; |
| | | self.http_get('api/strg/' + abs + '/' + kommando, function(responseText) { |
| | | if(kommando !== 'volup' && kommando !== 'voldn') { |
| | | self.meldung_mit_timeout(responseText, 1500); |
| | | console.log(kommando); |
| | | if(self.playingIndex > -1) { |
| | | if(kommando === 'stop') { |
| | | self.audioElem.pause(); |
| | | self.audioElem.currentTime = 0; |
| | | self.audioElem.removeEventListener("ended", self.nextTrack); |
| | | self.playingIndex = -1; |
| | | self.playState = 'stop'; |
| | | } else if(kommando === 'pause') { |
| | | if(self.playState === 'pause') { |
| | | self.playState = 'play'; |
| | | self.audioElem.play(); |
| | | } else if(self.playState === 'play') { |
| | | self.playState = 'pause'; |
| | | self.audioElem.pause(); |
| | | } |
| | | } else if(kommando === 'play') { |
| | | if(self.playingIndex < 0) { |
| | | self.nextTrack(); |
| | | } else { |
| | | self.audioElem.play(); |
| | | } |
| | | self.playState = 'play'; |
| | | } |
| | | }); |
| | | } else { |
| | | var abs = document.querySelector('#abspieler').value; |
| | | self.http_get('api/strg/' + abs + '/' + kommando, function(responseText) { |
| | | if(kommando !== 'volup' && kommando !== 'voldn') { |
| | | self.meldung_mit_timeout(responseText, 1500); |
| | | } |
| | | }); |
| | | } |
| | | }; |
| | | |
| | | this.hier_spielen = function() { |
| | |
| | | console.log( |
| | | "play playlist.value: " + document.querySelector('#playlist').value + |
| | | ", abspieler.value: " + document.querySelector('#abspieler').value); |
| | | // hier noch URL fuer Stream der Abspielliste abrufen |
| | | // Es muss auch noch die Funktion auf dem Server gabut werden, die |
| | | // eine Abspielliste als Stream liefert |
| | | url = 'Stream fuer Abspielliste ' + lst + ' noch nicht gebaut.'; |
| | | self.playingIndex = -1; |
| | | self.nextTrack(); |
| | | } |
| | | console.log('url: ' + url); |
| | | //window.open(url); |
| | | }; |
| | | |
| | | this.nextTrack = function() { |
| | | /* |
| | | |
| | | { |
| | | "katalogUrl":"/media", |
| | | "pfad":"/Musik/M/Bruno-Mars/", |
| | | "name":"04-Uptown-Funk.mp3", |
| | | "interpret":"Mark Ronson feat Bruno Mars", |
| | | "titelAnzName":"Uptown Funk", |
| | | "album":"Uptown Special Explicit" |
| | | } |
| | | |
| | | */ |
| | | //const plname = document.querySelector('#playlist').value; |
| | | if(self.playingIndex > -1) { |
| | | self.audioElem.removeEventListener("ended", self.nextTrack); |
| | | } else { |
| | | self.playingList = document.querySelector('#playlist').value; |
| | | } |
| | | self.playingIndex++; |
| | | const url = 'api/alist/' + self.playingList + "/" + self.playingIndex; |
| | | self.http_get(url, function(responseText){ |
| | | if(responseText === 'eom') { |
| | | // ende |
| | | self.audioElem.removeEventListener("ended", self.nextTrack); |
| | | self.playingIndex = -1; |
| | | self.playState = 'stop'; |
| | | } else { |
| | | const titel = JSON.parse(responseText); |
| | | console.log("titel: " + titel.name); |
| | | const titelUrl = self.getTitelFromJSONObj(titel); |
| | | //const titelElem = new Audio(titel); |
| | | self.audioElem = new Audio(titelUrl); |
| | | self.audioElem.addEventListener("ended", self.nextTrack); |
| | | self.audioCtx = new (window.AudioContext || window.webkitAudioContext)(); |
| | | const track = self.audioCtx.createMediaElementSource(self.audioElem); |
| | | track.connect(self.audioCtx.destination); |
| | | self.audioElem.play(); |
| | | self.playState = 'play'; |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | this.getTitelFromJSONObj = function(titelObj) { |
| | | //const audioElements = document.querySelectorAll('.entity-eintrag'); |
| | | const host = 'http://' + window.location.host + '/tango'; |
| | | const titel = host + titelObj.katalogUrl + titelObj.pfad + titelObj.name; |
| | | return titel; |
| | | }; |
| | | |
| | | this.gehe_zu_dialog_zeigen = function () { |
| | | self.dialog_laden_und_zeigen('data/tpl/gehe-zu.txt', '', function(){ |
| | | const form = document.querySelector('form'); |