{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 视频\n", "\n", "显示一个视频。\n", "\n", "- `src`: 视频源的URL或本地文件路径\n", "- `controls`: 是否显示视频控制,如播放、暂停和音量(默认值:`True`)\n", "- `autoplay`: 是否自动开始播放视频(默认值:`False`)\n", "- `muted`: 视频是否应初始为静音状态(默认值:`False`)\n", "- `loop`: 视频是否应该循环播放(默认值:`False`)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "查看[事件列表](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video#events),您可以使用通用事件订阅`on()`进行订阅。" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from nicegui import ui\n", "\n", "v = ui.video('https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4')\n", "v.on('ended', lambda _: ui.notify('Video playback completed'))\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 控制视频元素\n", "此演示展示了如何以编程方式播放、暂停和查找。" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "v = ui.video('https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4')\n", "ui.button('Play', on_click=v.play)\n", "ui.button('Pause', on_click=v.pause)\n", "ui.button('Jump to 0:05', on_click=lambda: v.seek(5))\n", "\n", "# ui.run()" ] } ], "metadata": { "kernelspec": { "display_name": "py311", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 2 }