Skip to main content

HTMLPlayer

一个简单的Python库,用于使用Microsoft Edge浏览器或系统默认浏览器播放HTML5视频。

安装

pip install htmlplayer

快速开始

基础用法

from htmlplayer import play_video

play_video('https://example.com/video.mp4')

指定窗口大小

play_video('https://example.com/video.mp4', width=1280, height=720)

仅使用Edge浏览器

from htmlplayer import play_with_edge

play_with_edge('https://example.com/video.mp4')

使用系统默认浏览器

from htmlplayer import play_with_browser

play_with_browser('https://example.com/video.mp4')

API 文档

play_video(url, width=None, height=None, use_edge=True, use_browser_fallback=True)

使用Edge浏览器或系统默认浏览器播放视频。

参数:

  • url (str): 视频URL地址
  • width (int, optional): 窗口宽度
  • height (int, optional): 窗口高度
  • use_edge (bool): 是否优先使用Edge浏览器,默认True
  • use_browser_fallback (bool): Edge不可用时是否使用默认浏览器,默认True

返回:

  • bool: 播放是否成功启动

play_with_edge(url, width=None, height=None)

仅使用Edge浏览器播放视频。

play_with_browser(url, width=None, height=None)

使用系统默认浏览器播放视频。

find_edge_browser()

查找Microsoft Edge浏览器的安装路径。

返回:

  • str or None: Edge浏览器的安装路径,若未找到返回None

calculate_window_size(width=None, height=None, scale=None)

根据视频宽高计算合适的窗口大小(严格等比缩放)。

参数:

  • width (int/float, optional): 视频宽度(像素),不传则使用屏幕宽度
  • height (int/float, optional): 视频高度(像素),不传则使用屏幕高度
  • scale (float, optional): 自定义缩放比例(相对屏幕),默认None表示自动计算

返回:

  • tuple: 包含窗口宽度和高度的元组 (final_width, final_height)

自动缩放规则:

  • 横屏视频(宽 >= 高):缩放到屏幕的 50%
  • 竖屏视频(宽 < 高):缩放到屏幕的 80%
  • 严格保持原视频纵横比

系统要求

  • 操作系统:Windows
  • Python 3.8+
  • Microsoft Edge浏览器(可选,推荐)

示例代码

安装后,你可以查看 examples/ 目录下的示例代码:

# 简单示例
python -c "import htmlplayer.examples.simple_example"

# 或找到安装位置查看文件
python -c "import htmlplayer; import os; print(os.path.join(os.path.dirname(htmlplayer.__file__), '..', 'examples'))"

示例文件:

  • simple_example.py - 基础使用示例
  • advanced_example.py - 高级功能和自定义配置

许可证

MIT License

Metadata

Release files for htmlplayer 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for htmlplayer 0.3.1
File Size Uploaded Provenance Actions
htmlplayer-0.3.1.tar.gz 6.3 kB Without provenance Details for htmlplayer-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for htmlplayer 0.3.1
File Interpreter ABI Platform Actions
htmlplayer-0.3.1-py3-none-any.whl Python 3 none any Details for htmlplayer-0.3.1-py3-none-any.whl

Total release size: 13.1 kB

Release files / htmlplayer-0.3.1.tar.gz

Download URL htmlplayer-0.3.1.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1fd4ba1ec843691cfd7ff016d8edbaa53fcc53bcec5048c3d8f6c81915391e42
BLAKE2b-256 checksum
How to use checksums
7f3f6a70348d85fe4916ad53ee81dfe94c7a68cb05558c764e10d9ceaf84c60f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / htmlplayer-0.3.1-py3-none-any.whl

Download URL htmlplayer-0.3.1-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16382c0ce9befca2b1bfa790430555694b2adbc17854b46abf6c09087eb48d2b
BLAKE2b-256 checksum
How to use checksums
4249ed5a2b381c7da2603bc0ddd05aef3941da4a6bcc73bd948e9cb52c4bba7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Security for htmlplayer 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page