Skip to content

Commit

Permalink
version 1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaokang2022 committed Sep 16, 2024
1 parent 850eb5a commit 14ce0c0
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 15 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,35 @@ Changelog / 更新日志
> * 🟠 **Deprecated / 弃用**
> * 🟤 **Refactored / 重构**
🔖 `1.0.3`
-----------

🟢 **Added / 新增**

- Added a left-click function to pause
新增了鼠标左键点击可以暂停的功能

- Added a function for the mouse wheel to adjust the volume
新增了鼠标滚轮可以调节音量的功能

- Added the display of video playback progress information
新增视频播放进度信息的显示

🟡 **Changed / 变更**

- Change the progress bar to a slider bar and you can drag the video progress
将进度条更改为滑动条,可以拖动视频进度了

🟣 **Fixed / 修复**

- Fixed a bug where video playback would cause continuous stuttering
修复了视频播放完成时会产生持续卡顿的 bug

🔵 **Optimized / 优化**

- Optimize the UI
优化 UI

🔖 `1.0.2`
-----------

Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ pip install tkintertools-media

The sample video is downloaded from: http://www.sample-videos.com/

![preview](./preview.png)
![preview-1](./preview-1.png)

![preview-2](./preview-2.png)

<details><summary>Code</summary>

Expand All @@ -53,7 +55,7 @@ import tkintertools as tkt
import tkintertools.media as media

root = tkt.Tk(title="tkintertools-media")
cv = media.VideoCanvas(root, keep_ratio="min", free_anchor=True, control=True, max_fps=60)
cv = media.VideoCanvas(root, keep_ratio="min", free_anchor=True, control=True)
cv.place(width=1280, height=720, x=640, y=360, anchor="center")
cv.play("your_video_file.mp4")
root.mainloop()
Expand Down
Binary file added preview-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added preview-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed preview.png
Binary file not shown.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
"Typing :: Typed",
]
dependencies = ["tkintertools==3.0.0rc1", "pillow>=10.0.0", "ffpyplayer>=4.5.0"]
dependencies = ["tkintertools==3.0.0rc2", "pillow>=10.0.0", "ffpyplayer>=4.5.0"]
dynamic = ["version"]

[project.urls]
Expand Down
2 changes: 1 addition & 1 deletion tkintertools/media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@

from .main import *

__version__ = "1.0.2"
__version__ = "1.0.3"
__author__ = "Xiaokang2022 <2951256653@qq.com>"
49 changes: 38 additions & 11 deletions tkintertools/media/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ def __init__(
self.delay = 1000 // max_fps
self._control = control
self._video = self.create_image(0, 0, anchor="nw")
self.bind("<ButtonRelease-1>",
lambda _: self.media.toggle_pause(), "+")

def _initialization(self) -> None:
tkintertools.core.containers.Canvas._initialization(self)
if self._control:
self.control()
self._control_ui()
self.bind("<Enter>", lambda _: self._an(True), "+")
self.bind("<Leave>", lambda _: self._an(False), "+")
self.bind("<MouseWheel>", lambda event: self.v.set(
self.v.get() + 0.05*((1, -1)[event.delta < 0]),
callback=True), "+")

def _refresh(self) -> None:
"""Refresh the canvas"""
Expand All @@ -70,35 +75,57 @@ def _refresh(self) -> None:
self.itemconfigure(self._video, image=self.frame)
if self._control:
self.p.set(pts / self.metadata["duration"])
self.t.set(f"{self._tiem_convert(
pts)} / {self._tiem_convert(self.metadata["duration"])}")
elif val == 'eof' and self._control:
self.media.set_pause(True)
self.p.set(1)
self.schedule = self.after(self.delay, self._refresh)

def _tiem_convert(self, t: float) -> str:
"""Convert seconds to a special format"""
m, s = divmod(round(t), 60)
return f"{m:02d}:{s:02d}"

def play(self, file: str) -> None:
"""Play the video"""
self.media = ffpyplayer.player.MediaPlayer(file, autoexit=True)
self.metadata = self.media.get_metadata()
self._refresh()

def control(self) -> None:
""""""
def _control_ui(self) -> None:
"""UI for bottom bar"""
self.bottom = tkintertools.Frame(
self, zoom_item=True, free_anchor=True)
self.bottom.place(width=1280, height=60, y=self._size[1])
self.t = tkintertools.standard.widgets.Text(
self.bottom, (215, 30), text="00:00 / 00:00", anchor="center")
tkintertools.standard.widgets.Button(
self.bottom, (10, 10), text="播放 / 暂停",
command=self.media.toggle_pause)
self.p = tkintertools.standard.widgets.ProgressBar(
self.bottom, (150, 20), (800, 20))
self.p = tkintertools.standard.widgets.Slider(
self.bottom, (300, 15), (650, 30),
command=lambda p: (
self.media.seek(p*self.metadata["duration"], relative=False),
self.t.set(f"{self._tiem_convert(
p*self.metadata["duration"])} / {
self._tiem_convert(self.metadata["duration"])}")))
tkintertools.standard.widgets.Text(
self.bottom, (1000, 30), text="音量", anchor="center")
tkintertools.standard.widgets.Slider(
self.bottom, (1050, 15), (200, 30),
self.v = tkintertools.standard.widgets.Slider(
self.bottom, (1040, 15), (150, 30),
command=self.media.set_volume, default=1)
tkintertools.standard.widgets.ToggleButton(
self.bottom, (1210, 10), text="全屏",
command=self.master.fullscreen
)

def _an(self, up: bool) -> None:
""""""
"""Animation for bottom bar"""
k = -1 if up else 1
tkintertools.animation.animations.MoveTkWidget(
self.bottom, 250, (0, self.bottom._size[1]*k), fps=60,
controller=tkintertools.animation.controllers.smooth).start()
dy = 0 if up else self.bottom._size[1]
tkintertools.animation.animations.Animation(
250, tkintertools.animation.controllers.smooth, fps=60,
callback=lambda p: self.bottom.place(
y=self._size[1] + self.bottom._size[1]*p*k - dy)
).start()

0 comments on commit 14ce0c0

Please sign in to comment.