Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add custom video player example #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions examples/CustomVideoPlayer/custom_video_player.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import streamlit
from streamlit import runtime
from streamlit.runtime import caching

import streamlit.components.v1 as components

_custom_videoplayer = components.declare_component(
"custom_videoplayer", url="http://localhost:3001",
)


def custom_videoplayer(data_or_filename, mimetype: str = "video/mp4", key: str = None):
dg = streamlit._main
coordinates = dg._get_delta_path_str()

if runtime.exists():
file_url = runtime.get_instance().media_file_mgr.add(
data_or_filename, mimetype, coordinates
)
caching.save_media_data(data_or_filename, mimetype, coordinates)
else:
# When running in "raw mode", we can't access the MediaFileManager.
file_url = ""

return _custom_videoplayer(file_url=file_url, key=key, default=None)


filepath = "./pexels-cottonbro-studio-6853337-338x640-25fps.mp4"
custom_videoplayer(filepath)
6 changes: 6 additions & 0 deletions examples/CustomVideoPlayer/frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Run the component's dev server on :3001
# (The Streamlit dev server already runs on :3000)
PORT=3001

# Don't automatically open the web browser on `npm run start`.
BROWSER=none
5 changes: 5 additions & 0 deletions examples/CustomVideoPlayer/frontend/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"endOfLine": "lf",
"semi": false,
"trailingComma": "es5"
}
Loading