M
M
MMMYIWW2017-03-02 15:17:11
PHP
MMMYIWW, 2017-03-02 15:17:11

Is it possible to get data from a constantly updated file?

Hello! Look, there is a file, for example, this one - " nashe1.hostingradio.ru/ultra-128.mp3 ". As you can see, this is an Internet radio - that is, this file is "dynamic". So, is it possible to somehow get its binary data? The task is that I need to get its data and process it using the WebAudioAPI - get the "arraybuffer" and execute "decodeAudioData", and then play this file. I know how to work with static audio files, but not with such ones. If you try to get the data of this file, they are "loaded" constantly and without a final result, that is, an endless and fruitless download. Is it possible to implement getting this data in real time in JS or in PHP? How can I explain this better:
1) The user enters the page and presses, say, the "Play" button
2) A request is made to " nashe1.hostingradio.ru/ultra-128.mp3 ", the server receives data from this source and returns them back (ajax) to page
3 ) JS receives this data (arraybuffer) and sends it to WebAudioAPI, which processes it (decodeAudioData), receives "getByteFrequencyData" and only then plays this file.

I have everything done already - getting "getByteFrequencyData" and playing the file, but only for "completed" files - static. I hope I have explained everything clearly. I would really appreciate your advice! Thank you!

* nashe1.hostingradio.ru/ultra-128.mp3 - for example.
I will describe in full what I need it for - visualization of Internet radio using three.js. Everything is done and working as it should. However, only with statics, with a flow, is another story that I cannot figure out - that's why I wrote here out of desperation.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stalker_RED, 2017-03-02
@MMMYIWW

Do n't bother with low level, use <audio>createAnalyser Demo: https://codepen.io/anon/pen/zZqqrW (had to tweak it a bit) Original (not working) : https://codepen.io/AfroDev/pen/MYOrvP network of dozens of visualizers, if anything.

M
MMMYIWW, 2017-03-03
@MMMYIWW

For those who need a solution:

var context = new (window.AudioContext || window.webkitAudioContext)();
var analyser = context.createAnalyser();
var audio  = document.querySelector('audio'); //Ваш аудио-элемент
var source = context.createMediaElementSource(audio);
source.connect(analyser);
source.connect(context.destination);
analyser.fftSize = 512;
var bufferLength = analyser.frequencyBinCount;
var dataArray = new Uint8Array(bufferLength);
// 
var update = function(){
  analyser.getByteFrequencyData(dataArray);
  	boost = 0;
   	for(var i = 0; i < bufferLength; i++){
    	     boost += dataArray[i];
  	}
  	boost = boost / dataArray.length;
  	return boost; //boost, нужный мне для визуализации в three.js
};
update(); //Вызывайте update с нужным вам интервалом, при помощи SetInterval().

Next, I take the "boost" value in three.js and interact with it.
Stalker_RED , thanks for the link to createAnalyser

A
Alex K, 2017-03-09
@Cyl

While the Russian Federation has not blocked https://www.linkedin.com/ it is possible and even necessary;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question