DSWaveformImage
DSWaveformImage copied to clipboard
Live waveform view for HLS audio streaming for SwiftUI
https://user-images.githubusercontent.com/88189594/182681882-091be2bd-9f8a-4780-ba52-68d26710ed91.mov
Basically this but for HLS audio urls.
Hey @Arnav-arw,
so as a disclaimer, I haven't actually done anything yet with HLS streams myself.
My understanding though is, that AVPlayer just plays them as it would any other regular local file.
That means, that you can use WaveformLiveView essentially exactly like the example use case from the readme:
see https://github.com/dmrschmidt/DSWaveformImage#waveformliveview---renders-a-live-waveform-from-01-normalized-samples
Only difference should pretty much be that you'll be using AVPlayer instead of AVAudioRecorder from the example.
So sth along the lines of. Beware that you'll need to refresh this of course in some Timer or similar
let waveformView = WaveformLiveView()
let player = AVPlayer(/*... however you init it*/)
player.isMeteringEnabled = true // required to get current power levels
// after all the other setup (omitted for focus) setup, periodically (every 20ms or so):
player.updateMeters() // gets the current value
let currentAmplitude = 1 - pow(10, player.averagePower(forChannel: 0) / 20)
waveformView.add(sample: currentAmplitude)
You could also have a look at this here, which may let you work off the stream a bit more "directly". Completely untested, I just came across this during googling: https://chritto.wordpress.com/2013/01/07/processing-avplayers-audio-with-mtaudioprocessingtap/
Closing due to inactivity. If this didn't help and the problem persists, please feel free to re-open this / open a new issue.