This release is a pre-release and may not be stable for production use.
pyxpo-video
A video player for pyxpo apps, written in Python. VideoView plays a local
file or an http(s) URL inside your layout, with the platform's own playback controls. It uses AVPlayer on iOS and
the Mac, VideoView on Android, and a <video> element on the web page and the desktop window.
import pyxpo_video as Video
Video.VideoView(source="/path/clip.mp4", style={"width": 270, "height": 480}) # plays at once
Features
- One component:
VideoViewsits in your layout like any other view and takes its size fromstyle. - Native players:
- iOS and Mac Catalyst: AVPlayer in an
AVPlayerViewController, with the system controls. - Android:
android.widget.VideoViewwith aMediaController. - Web page and desktop window: an HTML
<video>element.
- iOS and Mac Catalyst: AVPlayer in an
- Local files and URLs: a file path, a
file://URI or anhttp(s)URL. - Simple props:
playing,loop,muted,controlsandresize_mode("contain","cover","stretch"). - Events:
on_loadwith the duration and the video size,on_errorwith a message,on_endat the end. - Control from code:
ref.current.play(),.pause()and.seek(seconds). - Typed: ships
py.typed.
Contents
| If you are... | Start here |
|---|---|
| New to the package | Quick start → Sources → Props |
| Controlling playback from buttons | Play, pause and seek |
| Filling a frame or a card | Resize modes |
| Reacting to the video | Events and errors |
| Seeing it in a real app | Recipe: a preview of a file your app just made |
| Looking for exact signatures | API reference |
| Stuck | Testing · Troubleshooting · FAQ |
Platform support
| Target | Player | Notes |
|---|---|---|
| Android, API 24+ | android.widget.VideoView + MediaController |
resize_mode is always "contain". The controls show on a tap. |
| iOS 15+ | AVPlayer (AVPlayerViewController) |
All props. The controls hide while playing and come back on a tap. |
| Mac Catalyst | AVPlayer, same code as iOS | All props. |
Web page (pyxpo build web) |
<video> |
Local files come from the app's in-browser file system. |
Desktop window (pyxpo run desktop) |
<video> |
Local files come from the dev server with byte ranges, so seeking works. |
The formats are the platform's own. H.264 video with AAC audio in an .mp4 file plays everywhere.
Requires Python 3.9+ and pyxpo>=0.1.0a3.
Install
pip install pyxpo-video
Add the module to your app's pyproject.toml:
[tool.pyxpo]
modules = ["video"]
The module has native code, so rebuild the app after adding it (pyxpo run android or pyxpo run ios). It has no
config plugin and needs no permissions. Android apps already have the INTERNET permission for URLs.
Quick start
A player with its own Play, Pause and Restart buttons, and a status line:
import os
from pyxpo import Button, Text, View, component, use_ref, use_state
import pyxpo_video as Video
CLIP = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "assets", "clip.mp4")
@component
def Player():
player = use_ref(None)
info, set_info = use_state(None)
problem, set_problem = use_state("")
status = problem or ("%.1f s, %d x %d" % (info["duration"], info["width"], info["height"]) if info else "loading")
return View(
View(
Video.VideoView(ref=player, source=CLIP, playing=True, muted=True,
on_load=set_info, on_error=lambda e: set_problem(e["message"]),
style={"flex": 1}),
style={"width": 260, "height": 400, "borderRadius": 16, "overflow": "hidden",
"backgroundColor": "#000"},
),
Text(status),
View(
Button(title="Play", on_press=lambda: player.current.play()),
Button(title="Pause", on_press=lambda: player.current.pause()),
Button(title="Restart", on_press=lambda: player.current.seek(0)),
style={"flexDirection": "row", "gap": 8},
),
style={"flex": 1, "alignItems": "center", "justifyContent": "center"},
)
default = Player
pyxpo build copies the app's assets/ folder into the app, so assets/clip.mp4 sits next to app/ on every
platform. The screenshots above come from this app with one more button that switches resize_mode.
Sources
source takes one of these:
| Value | Example | Notes |
|---|---|---|
| A file path | "/data/user/0/com.acme.app/files/reel.mp4" |
Absolute paths are best. Build them from __file__ or a folder API. |
A file:// URI |
"file:///Users/me/reel%20one.mp4" |
Turned into a path; %20 and other escapes are decoded. Only local hosts (file:/// or file://localhost/). |
An http:// or https:// URL |
"https://example.com/clip.mp4" |
Streams. iOS blocks plain http:// to the internet (App Transport Security), so use https://. |
None |
Shows an empty black box and stops playback. |
Anything else (an empty string, rtsp://, a file:// URI with another host, a number) raises ValueError when the
component renders.
When source changes, the player loads the new video and fires on_load again.
Tip: When your app writes a new video to the same path, the player keeps the old one. Change the component's
key(for example to the file's modification time) to make a new player that loads the new file. The recipe shows this.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
source |
str or None |
None |
The video. See Sources. |
playing |
bool |
True |
Plays when True, pauses when False. It acts when it changes; the user can still play and pause with the controls. |
loop |
bool |
False |
Starts again at the end. on_end does not fire while looping. |
muted |
bool |
False |
No sound. Use it for videos that start by themselves. |
controls |
bool |
True |
Shows the platform's playback controls. |
resize_mode |
str |
"contain" |
"contain", "cover" or "stretch". See Resize modes. |
on_load |
callable |
None |
on_load(info) when the video is ready. |
on_error |
callable |
None |
on_error(error) when the video cannot play. |
on_end |
callable |
None |
on_end(None) when the video reaches its end (not with loop=True). |
style |
style | None |
Size and position. Give the player a size: a width and height, flex: 1, or aspectRatio. |
ref |
ref | ref.current is a VideoViewHandle. |
Other props (key, test_id, ...) pass through like on any view.
Play, pause and seek
Pass a ref and call the handle's methods from a button or an effect:
from pyxpo import Button, View, component, use_ref
import pyxpo_video as Video
@component
def Clip(path):
player = use_ref(None)
return View(
Video.VideoView(ref=player, source=path, playing=False, style={"width": "100%", "aspectRatio": 9 / 16}),
Button(title="Jump to 0:05", on_press=lambda: player.current.seek(5)),
)
| Method | What it does |
|---|---|
play() |
Starts or resumes playback. |
pause() |
Pauses playback. |
seek(seconds) |
Jumps to seconds from the start. seconds must be a number >= 0; anything else raises ValueError. |
The methods change the player, not the playing prop. When playing changes later, the prop wins again. To keep
both in step, hold playing in state and change the state instead of calling play() and pause().
The methods raise RuntimeError("the VideoView is not mounted") before the view is on screen, and a link error that
names pyxpo-video when the app was built without modules = ["video"].
Resize modes
resize_mode |
Result | iOS / Mac | Android | Web / desktop |
|---|---|---|---|---|
"contain" |
The whole video, with black bars where the shapes differ. | .resizeAspect |
yes | object-fit: contain |
"cover" |
Fills the box and crops the edges. | .resizeAspectFill |
shows "contain" |
object-fit: cover |
"stretch" |
Fills the box and distorts the picture. | .resize |
shows "contain" |
object-fit: fill |
For a frame that always fits, give the box the video's shape: style={"width": "100%", "aspectRatio": 9 / 16} for
a vertical reel. Then all three modes look the same on every platform.
Events and errors
| Event | Argument | When |
|---|---|---|
on_load |
{"duration": 8.0, "width": 720.0, "height": 1280.0} |
The video is ready. Seconds and pixels. duration is 0 for a live stream. |
on_error |
{"message": "..."} |
The file or URL cannot play. |
on_end |
None |
Playback reached the end and loop is False. |
The message comes from the platform, so its text differs:
| Platform | Typical message | What to do |
|---|---|---|
| iOS / Mac | AVFoundation's localizedDescription, for example "The file couldn't be opened." |
Check that the path exists and the format is H.264 or HEVC in .mp4 or .mov. |
| Android | cannot play the video (error 1, -2147483648) |
MediaPlayer error codes. 1, -1004 is an I/O error (missing file, network); 1, -2147483648 usually means an unsupported format. |
| Web / desktop | The browser's MediaError.message, or cannot play the video |
Check the browser console. |
A bad prop value (resize_mode="fill", source="") is a ValueError from Python, not an on_error call.
Web and desktop
pyxpo run desktop and the web build render VideoView as a <video> element with playsinline:
http(s)URLs load directly, so they follow the browser's CORS and mixed-content rules.- In the desktop window, local files come from the dev server at
/file, which answers byte-range requests. That lets the browser seek and lets WebKit play the file at all. - In the web build, local files come from the in-browser file system as
blob:URLs. - Browsers block sound in videos that start by themselves. Set
muted=Truewhenplaying=Trueat load, or start playback from a button press.
Recipe: a preview of a file your app just made
An app that renders a video (say, a reel) shows a spinner while it works and the finished file after. A changing
key reloads the player each time the file is written again:
import os
from pyxpo import ActivityIndicator, Text, View, component
import pyxpo_video as Video
@component
def Preview(path, rendering):
frame = {"width": 270, "height": 480, "borderRadius": 24, "overflow": "hidden", "backgroundColor": "#000"}
if rendering:
return View(ActivityIndicator(), Text("Rendering..."), style=dict(frame, justifyContent="center",
alignItems="center"))
if not os.path.exists(path):
return View(Text("No video yet", style={"color": "#fff"}), style=dict(frame, justifyContent="center",
alignItems="center"))
mtime = int(os.path.getmtime(path))
return Video.VideoView(source=path, playing=False, controls=True, style=frame, key="player-%d" % mtime)
playing=False waits for the user to press play in the controls.
Production checklist
- Ship H.264 + AAC in
.mp4for the widest support. HEVC is smaller but older Android phones cannot play it. - Use
https://URLs. iOS blocks plainhttp://, and Android release builds block it unless you setuses_cleartext_traffic = trueunder[tool.pyxpo.android]. - Give every
VideoViewa size instyle. A player with no size has zero height. - Set
muted=Truefor videos that play by themselves. - Handle
on_errorand show a message. Files go missing and networks fail. - Keep large videos out of
assets/: they go into the app bundle. Download them to a folder at run time instead. - Test on a real phone. The emulator and the simulator decode in software and can stutter where a phone does not.
Testing
VideoView renders a PxVideoView node, so the mock renderer shows its props and can fire its events:
from pyxpo import LocalChannel, component, create_app
from pyxpo.renderers.mock import MockRenderer
import pyxpo_video as Video
def test_shows_the_duration():
got = []
@component
def Root():
return Video.VideoView(source="/tmp/a.mp4", playing=False, on_load=got.append)
ch = LocalChannel()
r = MockRenderer(ch)
create_app(Root, ch)
(node,) = r.find_all("PxVideoView")
assert node.props["source"] == "/tmp/a.mp4" and node.props["playing"] is False
r.emit("load", node, {"value": {"duration": 8.0, "width": 720.0, "height": 1280.0}})
assert got[0]["duration"] == 8.0
play(), pause() and seek() call the native module. In a unit test, answer them with
pyxpo.module_testing.FakeBridge:
from pyxpo.module_testing import FakeBridge
with FakeBridge("android") as fb:
for m in ("play", "pause", "seek"):
fb.on("Video", m, lambda *a: None)
ref.current.seek(2) # ref from a mounted VideoView
assert fb.calls[-1][:3] == ("Video", "seek", (tag, 2.0))
Troubleshooting
| Problem | Cause and fix |
|---|---|
| The player is not there at all | It has no size. Give it width/height, flex: 1 or aspectRatio. |
A black box and no on_load |
Wrong path. Print os.path.exists(path). For bundled files, build the path from __file__. |
A black box on Android with playing=False |
Android's VideoView draws nothing until playback starts. Press play in the controls or call play(). |
on_error on iOS for an http:// URL |
App Transport Security. Use https://. |
| No sound | muted=True, the phone's silent switch on iOS, or the browser's autoplay rule on the web. |
cover looks like contain on Android |
Android supports "contain" only. Give the box the video's aspect ratio instead. |
| The old video still plays after the file changed | The source string is the same. Change key (see the recipe). |
RuntimeError: the VideoView is not mounted |
play() ran before the view was on screen, or after it was removed. Call it from on_load or a button. |
An error that names pyxpo-video |
The app was built without the module. Add modules = ["video"] and rebuild. |
| The controls are not visible on iOS | They hide while playing. Tap the video. |
FAQ
Can it play YouTube or Instagram links?
No. Those are web pages, not video files. source needs a direct link to a media file (.mp4, .mov, .m3u8).
Does it play HLS (.m3u8)?
On iOS, the Mac and Android, yes: AVPlayer and MediaPlayer play HLS. On the web, only Safari plays it natively.
Can it play in the background or picture-in-picture? Not in this version. The video pauses with the app.
Does it cache downloaded videos?
No. For offline playback, download the file first (for example with pyxpo-file-system) and pass the local path.
API reference
VideoView(...)
VideoView(source=None, playing=True, loop=False, muted=False, controls=True, resize_mode="contain",
on_load=None, on_error=None, on_end=None, style=None, **props)
A component. See Props. Raises ValueError for a bad source or resize_mode.
VideoViewHandle
ref.current of a mounted VideoView.
| Member | Returns | Raises |
|---|---|---|
play() |
None |
RuntimeError when not mounted; a link error without the module |
pause() |
None |
same |
seek(seconds: float) |
None |
ValueError for a negative, infinite or non-number value; same as above |
Constants
| Name | Value |
|---|---|
RESIZE_MODES |
("contain", "cover", "stretch") |
__version__ |
The package version |
License
MIT. See LICENSE.
Metadata
Release files for pyxpo-video 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyxpo_video-0.1.0a1.tar.gz | 24.2 kB | With provenance | Details for pyxpo_video-0.1.0a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyxpo_video-0.1.0a1-py3-none-any.whl | Python 3 | none | any | Details for pyxpo_video-0.1.0a1-py3-none-any.whl |
Total release size: 41.6 kB
Release files / pyxpo_video-0.1.0a1.tar.gz
| Download URL | pyxpo_video-0.1.0a1.tar.gz |
|---|---|
| Size | 24.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e30f748a459910b095a47b17d02a6e9bedbaf694299c8281212248339c2eabe
|
|
BLAKE2b-256 checksum How to use checksums |
1c6f7beca68bab24071f8149ccfa8c27c01e32e9e855bf038922d660bb837219
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logRelease files / pyxpo_video-0.1.0a1-py3-none-any.whl
| Download URL | pyxpo_video-0.1.0a1-py3-none-any.whl |
|---|---|
| Size | 17.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
18227590b5b3e43bfad5321c0f751a44d2802a88519d8ea2390d3adbb1225120
|
|
BLAKE2b-256 checksum How to use checksums |
5cda79d07882cef6dcf9754b2c60a9458bb8408d5fd5af395bb4d7b575e95fa9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logSecurity for pyxpo-video 0.1.0a1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyxpo_video-0.1.0a1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 29, 2026.
Transparency logA 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.