Hey, I'm trying to make a game with an online radio station tuner, but every time I update the stream data with a fresh chunk the playback stops. Therefore, I'm forced to play(). This results in very choppy audio.
If using large buffers for the stream, it will hiccup less frequently, but this will result in a long initial buffer time. This is still not ideal. I have tried to union stream.data with mp3_stream.data, but playback stops. No matter how I try to edit AudioStreamMP3's data, it will always stop the playback.
I have tried masking the hiccup with static and it sounds janky as heck.
I'm hoping there is way to mitigate this issue. It's driving me nuts. Do you think it's worth creating a second AudioStreamPlayer to switch between the two? I'd imagine it'd be difficult to sync these up.
export(String) var station_name
export(String) var station_endpoint_url = "126.96.36.199"
export(int, 0, 65535) var station_endpoint_port = 8087
export(int, 0, 256) var buffer_kb = 64
export(float, 0, 1, 0.01) var frequency = .5
export(float, 87.9, 107.9, 0.1) var channel = 97.9
export(float, .05, .15) var bandwidth = .1
export(float, 0, 1) var signal_strength = 1
export(String, MULTILINE) var http_request = "GET / HTTP/1.1\n\n"
var mp3_stream = AudioStreamMP3.new()
var streaming = true
var stream_peer = StreamPeerTCP.new()
http_request = http_request.to_utf8()
if stream_peer.get_status() == stream_peer.STATUS_CONNECTED:
var available_bytes = stream_peer.get_available_bytes()
# When payload is ready, update the stream
if available_bytes >= buffer_kb * 1000:
mp3_stream.data = stream_peer.get_data(available_bytes)
stream = mp3_stream