File size: 6,167 Bytes
dc1e92f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
465ffdd
dc1e92f
 
 
 
 
 
 
 
 
 
465ffdd
dc1e92f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<!DOCTYPE html>
<html>

<head>
    <title>FoxDot Stream Test</title>
    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            padding: 40px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            min-height: 100vh;
            margin: 0;
        }

        .container {
            max-width: 600px;
            margin: 0 auto;
            background: rgba(255, 255, 255, 0.1);
            backdrop-filter: blur(10px);
            padding: 30px;
            border-radius: 15px;
            box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37);
        }

        h1 {
            text-align: center;
            margin-bottom: 10px;
        }

        .subtitle {
            text-align: center;
            opacity: 0.8;
            margin-bottom: 30px;
        }

        audio {
            width: 100%;
            margin: 20px 0;
            border-radius: 10px;
        }

        .status {
            padding: 15px;
            background: rgba(0, 0, 0, 0.3);
            border-radius: 8px;
            margin: 15px 0;
        }

        .status-indicator {
            display: inline-block;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            margin-right: 8px;
            animation: pulse 2s ease-in-out infinite;
        }

        .status-connecting {
            background: #ffd700;
        }

        .status-playing {
            background: #00ff00;
        }

        .status-error {
            background: #ff0000;
            animation: none;
        }

        .status-buffering {
            background: #ffa500;
        }

        @keyframes pulse {

            0%,
            100% {
                opacity: 1;
            }

            50% {
                opacity: 0.5;
            }
        }

        .info {
            background: rgba(0, 0, 0, 0.2);
            padding: 15px;
            border-radius: 8px;
            margin-top: 20px;
            font-size: 14px;
        }

        .info code {
            background: rgba(0, 0, 0, 0.3);
            padding: 2px 6px;
            border-radius: 3px;
            font-family: 'Courier New', monospace;
        }
    </style>
</head>

<body>
    <div class="container">
        <h1>🎵 FoxDot Audio Stream</h1>
        <p class="subtitle">Live audio streaming from SuperCollider</p>

        <audio id="audioPlayer" controls autoplay>
            <source src="http://localhost:8000/stream.mp3" type="audio/mpeg">
            Your browser does not support the audio element.
        </audio>

        <div class="status">
            <span id="statusIndicator" class="status-indicator status-connecting"></span>
            <strong>Status:</strong> <span id="statusText">Connecting...</span>
        </div>

        <div class="info">
            <strong>Stream Info:</strong><br>
            URL: <code id="streamUrl">http://localhost:8000/stream.mp3</code><br>
            Format: <code>MP3 (128kbps)</code><br>
            Source: <code>SuperCollider → JACK → FFmpeg → Icecast</code>
        </div>

        <div class="info" id="debugInfo" style="display: none;">
            <strong>Debug Info:</strong><br>
            <div id="debugText"></div>
        </div>
    </div>

    <script>
        const audio = document.getElementById('audioPlayer');
        const statusText = document.getElementById('statusText');
        const statusIndicator = document.getElementById('statusIndicator');
        const debugInfo = document.getElementById('debugInfo');
        const debugText = document.getElementById('debugText');

        function updateStatus(status, message) {
            statusText.innerText = message;
            statusIndicator.className = 'status-indicator status-' + status;
        }

        function log(message) {
            const timestamp = new Date().toLocaleTimeString();
            debugText.innerHTML += `[${timestamp}] ${message}<br>`;
            debugInfo.style.display = 'block';
            console.log(message);
        }

        audio.onloadstart = () => {
            updateStatus('connecting', 'Loading stream...');
            log('Loading stream from /stream');
        };

        audio.oncanplay = () => {
            updateStatus('playing', 'Ready to play');
            log('Stream is ready to play');
        };

        audio.onplaying = () => {
            updateStatus('playing', 'Playing ♪');
            log('Stream is playing');
        };

        audio.onwaiting = () => {
            updateStatus('buffering', 'Buffering...');
            log('Buffering stream data');
        };

        audio.onpause = () => {
            updateStatus('connecting', 'Paused');
            log('Stream paused');
        };

        audio.onerror = (e) => {
            updateStatus('error', 'Error loading stream');
            const error = audio.error;
            let errorMsg = 'Unknown error';
            if (error) {
                switch (error.code) {
                    case 1: errorMsg = 'MEDIA_ERR_ABORTED - Playback aborted'; break;
                    case 2: errorMsg = 'MEDIA_ERR_NETWORK - Network error'; break;
                    case 3: errorMsg = 'MEDIA_ERR_DECODE - Decoding error'; break;
                    case 4: errorMsg = 'MEDIA_ERR_SRC_NOT_SUPPORTED - Stream not supported'; break;
                }
            }
            log(`ERROR: ${errorMsg}`);

            // Try to get more info about the stream
            fetch('/stream', { method: 'HEAD' })
                .then(response => {
                    log(`Stream endpoint status: ${response.status}`);
                    log(`Content-Type: ${response.headers.get('content-type')}`);
                })
                .catch(err => {
                    log(`Cannot reach stream endpoint: ${err.message}`);
                });
        };

        // Show current URL
        document.getElementById('streamUrl').innerText = window.location.origin + '/stream';

        // Initial log
        log('Page loaded, attempting to connect to stream');
    </script>
</body>

</html>