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.**")