File size: 1,142 Bytes
1f16925
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import base64

from streamlit.components.v1 import html

st.title("Video Player App")

video_file_path = "D:\\huggingface\\KHome\\digitalhuman.mp4"
# 读取视频文件的内容
with open(video_file_path, "rb") as video_file:
    video_bytes = video_file.read()
    video_base64 = base64.b64encode(video_bytes).decode('utf-8')

STOPPED_STATE = f"""
    <video id="videoPlayer" width="320" height="240" controls>
      <source src="data:video/mp4;base64,{video_base64}" type="video/mp4">
      Your browser does not support the video tag.
    </video>
    """

PLAYING_STATE = f"""
    <video id="videoPlayer" width="320" height="240" controls autoplay>
      <source src="data:video/mp4;base64,{video_base64}" type="video/mp4">
      Your browser does not support the video tag.
    </video>
    """


playstate = st.session_state.get("playstate")
if not playstate:
    playstate = STOPPED_STATE
st.markdown(playstate, unsafe_allow_html=True)

# 播放按钮
if st.button("Play"):
    st.session_state["playstate"] = PLAYING_STATE

# 暂停按钮
if st.button("Pause"):
    st.session_state["playstate"] = STOPPED_STATE