Skip to main content

一个简单的HTML视频播放器,使用Edge浏览器或系统默认浏览器播放视频

Project description

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)

自动缩放规则:

  • 竖屏视频 (宽高比 <= 0.6): 自动使用 90% 尺寸
  • 高度 >= 1080: 自动使用 50% 尺寸
  • 高度 >= 720: 自动使用 60% 尺寸
  • 高度 >= 480: 自动使用 100% 尺寸

系统要求

  • 操作系统: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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

htmlplayer-0.2.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

htmlplayer-0.2.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file htmlplayer-0.2.0.tar.gz.

File metadata

  • Download URL: htmlplayer-0.2.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for htmlplayer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 474e1da98a2e58b8fc7d6f82c23b85b1ef9e2a9aa777d7b3e49d95b2ee2d8429
MD5 7eb5995911ea3d29ffffe74d0c0da81d
BLAKE2b-256 d073966bb3a8291c7a6abff951450fe7530900fa534c7ac72d40c22a0bc6dc08

See more details on using hashes here.

File details

Details for the file htmlplayer-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: htmlplayer-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for htmlplayer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9965f2b11ea12d9e31f2dba094c3e931d991f5b992eb3f61eca8c333410fc65
MD5 2ceae36c337936a1651b62c4f6d16a0a
BLAKE2b-256 3ac41ab544f9d150d11d9d86848f131560ca264be6d48bd52dbc9a788c596b3c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page