PSD-Tutorials.de
Forum für Design, Fotografie & Bildbearbeitung
Tutkit
Agentur
Hilfe
Kontakt
Start
Forum
Aktuelles
Besonderer Inhalt
Foren durchsuchen
Tutorials
News
Anmelden
Kostenlos registrieren
Aktuelles
Suche
Suche
Nur Titel durchsuchen
Von:
Menü
Anmelden
Kostenlos registrieren
App installieren
Installieren
JavaScript ist deaktiviert. Für eine bessere Darstellung aktiviere bitte JavaScript in deinem Browser, bevor du fortfährst.
Du verwendest einen veralteten Browser. Es ist möglich, dass diese oder andere Websites nicht korrekt angezeigt werden.
Du solltest ein Upgrade durchführen oder einen
alternativen Browser
verwenden.
Antworten auf deine Fragen:
Neues Thema erstellen
Start
Forum
Sonstiges
Webdesign, Webentwicklung & Programmierung
PHP, Javascript, jQuery, Ajax, nodeJS, MySQL...
Javascript Frage
Beitrag
<blockquote data-quote="consansri" data-source="post: 2715699"><p>Hallo,</p><p></p><p>ich bin gerade daran einen Audiovisualizer für einen eigenen Webplayer zu programmieren.</p><p>Mein Ziel ist es auf einem Canvas Objekt immer die Frequenzen des gerade spielenden Audio Objekts anzuzeigen.</p><p></p><p>Zur Erklärung:</p><p>Immer wenn Play gedrückt wird die initPlayer Funktion mit dem entsprechenden audioElement aufgerufen.</p><p></p><p>Code des Visualizers:</p><p></p><p>var canvas, ctx, source, context, analyser, fbc_array, bars, bar_x, bar_width, bar_height;</p><p>var audio = [document.getElementById("aBleibBeiUns"), document.getElementById("aOffline"), document.getElementById("aLeuchtturm"), document.getElementById("aImmerBegleiten"), document.getElementById("aCan'tHelpFallingInLove"), document.getElementById("aDerGedanke"), document.getElementById("aGefälltMir"),document.getElementById("aGL713"),document.getElementById("aDuBistDa"),document.getElementById("aAllOfMe"),document.getElementById("aCelloSuiteNo2"),document.getElementById("aDerSchwan"),document.getElementById("aRhapsodie")]; </p><p></p><p>function initPlayer(audio){</p><p> </p><p> document.getElementById('audioselect').appendChild(audio);</p><p> context = new AudioContext(); //DIE ANZAHL IST AUF 6 BESCHRÄNKT</p><p> </p><p> analyser = context.createAnalyser();</p><p> canvas = document.getElementById('canvas');</p><p> ctx = canvas.getContext('2d');</p><p> </p><p> try{</p><p> source = context.createMediaElementSource(audio); //WIE KANN ICH DAS SOURCE ELEMENT IMMER WIEDER NEU ERSTELLEN BZW. DIE VERBINDUNG MIT DER VORHERIGEN SOURCE NODE ENTFERNEN?</p><p> source.connect(analyser);</p><p> }catch(e){console.log(e);}</p><p> analyser.connect(context.destination);</p><p> </p><p> new frameLooper(); </p><p>}</p><p>//loop Grafik </p><p>function frameLooper(){</p><p> </p><p> window.requestAnimationFrame(frameLooper);</p><p> fbc_array = new Uint8Array(analyser.frequencyBinCount); </p><p> analyser.getByteFrequencyData(fbc_array);</p><p> ctx.clearRect(0,0, canvas.width, canvas.height);</p><p> ctx.fillStyle = '#333'; //Color of the Bars</p><p> bars = 400;</p><p> for (var i = 0; i < bars; i++){</p><p> bar_x = i * 6;</p><p> bar_width = 5;</p><p> bar_height = -(fbc_array<em> / 2);</em></p><p><em> //fillRect(x,y,width,height) </em></p><p><em> ctx.fillRect(bar_x, canvas.height, bar_width, bar_height); </em></p><p> <em>} </em></p><p><em>}</em></p><p><em></em></p><p><em>Und hier noch der Code aus dem die Funktion ausgeführt wird:</em></p><p><em>function aselect(snmbr){ </em></p><p> <em>var audio = [document.getElementById("aBleibBeiUns"), document.getElementById("aOffline"), document.getElementById("aLeuchtturm"), document.getElementById("aImmerBegleiten"), document.getElementById("aCan'tHelpFallingInLove"), document.getElementById("aDerGedanke"), document.getElementById("aGefälltMir"),document.getElementById("aGL713"),document.getElementById("aDuBistDa"),document.getElementById("aAllOfMe"),document.getElementById("aCelloSuiteNo2"),document.getElementById("aDerSchwan"),document.getElementById("aRhapsodie")]; </em></p><p><em></em></p><p> <em>if(!audio[snmbr].paused){ </em></p><p><em> audio[snmbr].pause(); </em></p><p><em> document.getElementById("a"+snmbr).style.backgroundColor="rgba(241,241,241, .8)";</em></p><p><em> document.getElementById("at"+snmbr).style.color="#333"; </em></p><p> <em>} else if(audio[snmbr].paused){ </em></p><p><em> audio[snmbr].play(); </em></p><p><em> new initPlayer(audio[snmbr], snmbr); // AUFRUF</em></p><p><em> audio[snmbr].volume = document.getElementById("currentvolume").value/100;</em></p><p><em> new playtime(snmbr);</em></p><p> <em>}</em></p><p> <em>for(var i=0;i < audio.length; i++){</em></p><p><em> if(i != snmbr){ </em></p><p><em> audio<em>.pause();</em></em></p><p><em><em> audio<em>.currentTime = 0;</em></em></em></p><p><em><em><em> }</em></em></em></p><p> <em><em><em>} </em></em></em></p><p><em><em><em>}</em></em></em></p></blockquote><p></p>
[QUOTE="consansri, post: 2715699"] Hallo, ich bin gerade daran einen Audiovisualizer für einen eigenen Webplayer zu programmieren. Mein Ziel ist es auf einem Canvas Objekt immer die Frequenzen des gerade spielenden Audio Objekts anzuzeigen. Zur Erklärung: Immer wenn Play gedrückt wird die initPlayer Funktion mit dem entsprechenden audioElement aufgerufen. Code des Visualizers: var canvas, ctx, source, context, analyser, fbc_array, bars, bar_x, bar_width, bar_height; var audio = [document.getElementById("aBleibBeiUns"), document.getElementById("aOffline"), document.getElementById("aLeuchtturm"), document.getElementById("aImmerBegleiten"), document.getElementById("aCan'tHelpFallingInLove"), document.getElementById("aDerGedanke"), document.getElementById("aGefälltMir"),document.getElementById("aGL713"),document.getElementById("aDuBistDa"),document.getElementById("aAllOfMe"),document.getElementById("aCelloSuiteNo2"),document.getElementById("aDerSchwan"),document.getElementById("aRhapsodie")]; function initPlayer(audio){ document.getElementById('audioselect').appendChild(audio); context = new AudioContext(); //DIE ANZAHL IST AUF 6 BESCHRÄNKT analyser = context.createAnalyser(); canvas = document.getElementById('canvas'); ctx = canvas.getContext('2d'); try{ source = context.createMediaElementSource(audio); //WIE KANN ICH DAS SOURCE ELEMENT IMMER WIEDER NEU ERSTELLEN BZW. DIE VERBINDUNG MIT DER VORHERIGEN SOURCE NODE ENTFERNEN? source.connect(analyser); }catch(e){console.log(e);} analyser.connect(context.destination); new frameLooper(); } //loop Grafik function frameLooper(){ window.requestAnimationFrame(frameLooper); fbc_array = new Uint8Array(analyser.frequencyBinCount); analyser.getByteFrequencyData(fbc_array); ctx.clearRect(0,0, canvas.width, canvas.height); ctx.fillStyle = '#333'; //Color of the Bars bars = 400; for (var i = 0; i < bars; i++){ bar_x = i * 6; bar_width = 5; bar_height = -(fbc_array[i] / 2); //fillRect(x,y,width,height) ctx.fillRect(bar_x, canvas.height, bar_width, bar_height); } } Und hier noch der Code aus dem die Funktion ausgeführt wird: function aselect(snmbr){ var audio = [document.getElementById("aBleibBeiUns"), document.getElementById("aOffline"), document.getElementById("aLeuchtturm"), document.getElementById("aImmerBegleiten"), document.getElementById("aCan'tHelpFallingInLove"), document.getElementById("aDerGedanke"), document.getElementById("aGefälltMir"),document.getElementById("aGL713"),document.getElementById("aDuBistDa"),document.getElementById("aAllOfMe"),document.getElementById("aCelloSuiteNo2"),document.getElementById("aDerSchwan"),document.getElementById("aRhapsodie")]; if(!audio[snmbr].paused){ audio[snmbr].pause(); document.getElementById("a"+snmbr).style.backgroundColor="rgba(241,241,241, .8)"; document.getElementById("at"+snmbr).style.color="#333"; } else if(audio[snmbr].paused){ audio[snmbr].play(); new initPlayer(audio[snmbr], snmbr); // AUFRUF audio[snmbr].volume = document.getElementById("currentvolume").value/100; new playtime(snmbr); } for(var i=0;i < audio.length; i++){ if(i != snmbr){ audio[i].pause(); audio[i].currentTime = 0; } } }[/i][/i][/i] [/QUOTE]
Bilder bitte
hier hochladen
und danach über das Bild-Icon (Direktlink vorher kopieren) platzieren.
Zitate einfügen…
Authentifizierung
Wenn ▲ = 5, ▼ = 2 und ■ = 7, was ist ▲ × ▼ + ■?
Antworten
Start
Forum
Sonstiges
Webdesign, Webentwicklung & Programmierung
PHP, Javascript, jQuery, Ajax, nodeJS, MySQL...
Javascript Frage
Oben