Spaces:
Sleeping
Sleeping
bugfix
Browse files- src/streamlit_app.py +31 -19
src/streamlit_app.py
CHANGED
|
@@ -201,30 +201,42 @@ with tab3:
|
|
| 201 |
st.session_state.time_bridge_initialized = True
|
| 202 |
debug_log("Time bridge initialized successfully", "STATE")
|
| 203 |
|
| 204 |
-
#
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
if (event.data.type === 'currentTimeUpdate') {
|
| 210 |
-
// Trigger Streamlit rerun by setting a dummy component value
|
| 211 |
-
Streamlit.setComponentValue(event.data.time);
|
| 212 |
-
}
|
| 213 |
-
});
|
| 214 |
-
</script>
|
| 215 |
-
""",
|
| 216 |
-
height=0
|
| 217 |
-
)
|
| 218 |
|
| 219 |
-
#
|
| 220 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
try:
|
| 222 |
-
new_time = float(
|
| 223 |
if new_time != st.session_state.current_time:
|
| 224 |
st.session_state.current_time = new_time
|
| 225 |
debug_log(f"Current playback time updated: {new_time:.2f} seconds", "STATE")
|
| 226 |
-
except
|
| 227 |
-
debug_log(f"Invalid time received: {
|
| 228 |
# Create dummy component to receive time updates
|
| 229 |
current_time = st.session_state.current_time
|
| 230 |
debug_log(f"Current playback time: {current_time:.2f} seconds", "STATE")
|
|
|
|
| 201 |
st.session_state.time_bridge_initialized = True
|
| 202 |
debug_log("Time bridge initialized successfully", "STATE")
|
| 203 |
|
| 204 |
+
# ===== Time Receiver via Hidden Input =====
|
| 205 |
+
time_input_key = "audio_current_time_input"
|
| 206 |
+
|
| 207 |
+
# Hidden input to receive time value
|
| 208 |
+
time_input = st.text_input("", value="", label_visibility="collapsed", key=time_input_key, disabled=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
|
| 210 |
+
# Inject JS to update the hidden input
|
| 211 |
+
st.components.v1.html(f"""
|
| 212 |
+
<script>
|
| 213 |
+
window.addEventListener('message', (event) => {{
|
| 214 |
+
if (event.data.type === 'currentTimeUpdate') {{
|
| 215 |
+
const time = event.data.time;
|
| 216 |
+
const input = parent.document.querySelector("input[key='{time_input_key}']");
|
| 217 |
+
if (input) {{
|
| 218 |
+
const nativeInputValueSetter = Object.getOwnPropertyDescriptor(
|
| 219 |
+
window.HTMLInputElement.prototype,
|
| 220 |
+
"value"
|
| 221 |
+
).set;
|
| 222 |
+
nativeInputValueSetter.call(input, time);
|
| 223 |
+
const event = new Event('input', {{ bubbles: true }});
|
| 224 |
+
input.dispatchEvent(event);
|
| 225 |
+
}}
|
| 226 |
+
}}
|
| 227 |
+
}});
|
| 228 |
+
</script>
|
| 229 |
+
""", height=0)
|
| 230 |
+
|
| 231 |
+
# Update session state time if changed
|
| 232 |
+
if time_input and time_input != "":
|
| 233 |
try:
|
| 234 |
+
new_time = float(time_input)
|
| 235 |
if new_time != st.session_state.current_time:
|
| 236 |
st.session_state.current_time = new_time
|
| 237 |
debug_log(f"Current playback time updated: {new_time:.2f} seconds", "STATE")
|
| 238 |
+
except Exception as e:
|
| 239 |
+
debug_log(f"Invalid time received: {time_input} - {e}", "WARN")
|
| 240 |
# Create dummy component to receive time updates
|
| 241 |
current_time = st.session_state.current_time
|
| 242 |
debug_log(f"Current playback time: {current_time:.2f} seconds", "STATE")
|