Spaces:
Build error
Build error
File size: 2,316 Bytes
38ed52d 82c9d19 38ed52d 82c9d19 38ed52d 3aa3494 82c9d19 38ed52d 82c9d19 38ed52d 82c9d19 38ed52d 82c9d19 38ed52d 82c9d19 38ed52d 82c9d19 38ed52d 82c9d19 38ed52d 3aa3494 82c9d19 | 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 | import streamlit as st
import time
# Title of the app
st.title("Simple Online Video Player")
# Create session state to track video state
if 'video_url' not in st.session_state:
st.session_state.video_url = ''
if 'playing' not in st.session_state:
st.session_state.playing = False
if 'paused' not in st.session_state:
st.session_state.paused = False
if 'video_progress' not in st.session_state:
st.session_state.video_progress = 0
# 1. Open Button (Text Input for URL)
st.write("**Enter the video URL (e.g., .mp4 file link):**")
video_url = st.text_input("Video URL", value=st.session_state.video_url)
# Update session state with video URL
if video_url:
st.session_state.video_url = video_url
# 2. Playback Controls: Play, Pause, Stop buttons
if video_url:
play_button = st.button("Play")
pause_button = st.button("Pause")
stop_button = st.button("Stop")
# Handle Play Button
if play_button:
st.session_state.playing = True
st.session_state.paused = False
st.session_state.video_progress = 0
# Handle Pause Button
if pause_button and st.session_state.playing:
st.session_state.playing = False
st.session_state.paused = True
# Handle Stop Button
if stop_button:
st.session_state.playing = False
st.session_state.paused = False
st.session_state.video_progress = 0 # Reset progress
# 3. Playback Status Bar and Progress
if video_url:
# Show the current status of the video
if st.session_state.playing:
st.session_state.video_progress += 1 # Simulate time passing
st.write(f"**Playing**: Current Time: {st.session_state.video_progress} seconds")
elif st.session_state.paused:
st.write(f"**Paused**: Current Time: {st.session_state.video_progress} seconds")
else:
st.write(f"**Stopped**: Video Reset to Start")
# Display a progress bar based on current time
progress = st.progress(st.session_state.video_progress % 100)
# Sleep for a second to simulate real-time updates (this helps in debugging)
time.sleep(1)
# Display the video if Play is clicked
if video_url and st.session_state.playing:
st.video(video_url, start_time=st.session_state.video_progress)
else:
st.write("**Enter a valid URL to play the video.**")
|