Last active
September 19, 2025 13:49
-
-
Save ZiTAL/61faf442cae8076199e5e0c91b825edc to your computer and use it in GitHub Desktop.
stream to hls:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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