Skip to content

Instantly share code, notes, and snippets.

@ZiTAL
Last active September 19, 2025 13:49
Show Gist options
  • Select an option

  • Save ZiTAL/61faf442cae8076199e5e0c91b825edc to your computer and use it in GitHub Desktop.

Select an option

Save ZiTAL/61faf442cae8076199e5e0c91b825edc to your computer and use it in GitHub Desktop.
stream to hls:
ffmpeg -i https://irratia.itsuki.freemyip.com/itsuki.mp3 \
-c:a aac -b:a 256k -ar 48000 \
-f hls \
-hls_time 10 \
-hls_list_size 8640 \
-hls_flags delete_segments+append_list \
-hls_segment_filename /tmp/hls/itsuki_%05d.ts \
/tmp/hls/itsuki.m3u8
<?php
header("Access-Control-Allow-Origin: *");
?>
<audio controls src="http://localhost:8000/hls/itsuki.m3u8"></audio>
<button>online</button>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<script>
(function()
{
const offset = 20
const audio = document.querySelector('audio')
const button = document.querySelector('button')
const url = audio.src
if (Hls.isSupported())
{
const hls = new Hls()
hls.loadSource(url)
hls.attachMedia(audio)
hls.on(Hls.Events.MANIFEST_PARSED, function ()
{
online()
})
audio.addEventListener('seeking', () =>
{
let current_time = audio.currentTime
let duration = audio.duration
if (current_time >= duration)
online()
})
button.addEventListener('click', () =>
{
online()
})
}
else if (audio.canPlayType('application/vnd.apple.mpegurl'))
{
audio.src = url
button.addEventListener('click', () =>
{
online()
})
}
function online()
{
//hls.startLoad(-offset);
audio.currentTime = audio.duration - offset
if (!isAudioPlaying(audio))
audio.play()
}
function isAudioPlaying(audio_element)
{
return !audio_element.paused && audio_element.currentTime > 0 && !audio_element.ended;
}
})()
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment