Spaces:
Runtime error
Runtime error
import os | |
import streamlit as st | |
# These are the formats supported in Streamlit right now. | |
VIDEO_EXTENSIONS = ["mp4", "ogv", "m4v", "webm"] | |
# For sample video files, try the Internet Archive, or download a few samples here: | |
# http://techslides.com/sample-webm-ogg-and-mp4-video-files-for-html5 | |
st.title("Video Player") | |
st.header("Local video files") | |
st.write( | |
"You can use st.video to play a locally-stored video by supplying it with a valid filesystem path." | |
) | |
def get_video_files_in_dir(directory): | |
out = [] | |
for item in os.listdir(directory): | |
try: | |
name, ext = item.split(".") | |
except: | |
continue | |
if name and ext: | |
if ext in VIDEO_EXTENSIONS: | |
out.append(item) | |
return out | |
avdir = os.path.expanduser("~") | |
files = get_video_files_in_dir(avdir) | |
if len(files) == 0: | |
st.write( | |
"Put some video files in your home directory (%s) to activate this player." | |
% avdir | |
) | |
else: | |
filename = st.selectbox( | |
"Select a video file from your home directory (%s) to play" % avdir, | |
files, | |
0, | |
) | |
st.video(os.path.join(avdir, filename)) | |
st.header("Remote video playback") | |
st.write("st.video allows a variety of HTML5 supported video links, including YouTube.") | |
def shorten_vid_option(opt): | |
return opt.split("/")[-1] | |
# A random sampling of videos found around the web. We should replace | |
# these with those sourced from the streamlit community if possible! | |
vidurl = st.selectbox( | |
"Pick a video to play", | |
( | |
"https://youtu.be/IoQsyHVFflU", | |
"https://youtu.be/ZT3_2X7Txu0?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1", | |
"https://youtu.be/2N83yzUcomc?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1", | |
"https://youtu.be/0i3U47OQs0E?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1", | |
"https://youtu.be/L8ObyHp9PY0?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1", | |
"https://youtu.be/x9vRg5KmLIo?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1", | |
"https://youtu.be/ZEchaKXaaas?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1", | |
"https://youtu.be/5yToL7ymfNo?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1", | |
"https://youtu.be/N2hM3RYdyrE?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1", | |
"https://youtu.be/Kd8OAVRyDc4?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1", | |
"https://youtu.be/OsRBhgTxYPQ?list=PLHgX2IExbFosM9aYef9-1ymyx3QNUw3w1", | |
"https://youtu.be/V7rJ3eS1dHQ", | |
"https://youtu.be/w7EPhC1WEvE" | |
), | |
0, | |
shorten_vid_option, | |
) | |
st.video(vidurl) |