Cloudflare Stream Player -- Customization and API
In this tutorial, you'll learn about Cloudflare Stream Player. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
This tutorial covers how to customize the Cloudflare Stream player using skin properties, JavaScript API methods, and event listeners to build a tailored video playback experience for your application.
Why the Stream Player Matters
The default Cloudflare Stream player works out of the box, but most applications require custom branding, specific controls, and integration with analytics or advertising systems. The Stream player exposes a rich JavaScript API that lets you control playback programmatically, listen for events, change styles, and integrate with third-party services. This flexibility makes it suitable for everything from simple video pages to complex video platforms.
Real-world use: DodaZIP uses the Stream player API to track user engagement with tutorial videos. Custom events send play, pause, and completion data to an analytics pipeline, helping the team identify which tutorials retain viewers and which need improvement.
Stream Player Customization Flow
flowchart TD A[Load Stream player SDK] --> B[Create player instance] B --> C[Apply skin properties] C --> D[Attach event listeners] D --> E[Control via API methods] E --> F[Handle errors gracefully] F --> G[Integrate with analytics] style B fill:#f90,color:#fff style D fill:#f90,color:#fff style F fill:#f90,color:#fff
Basic Player Embed with Custom Skin
The Stream player accepts skin properties that control colors, fonts, and control bar visibility. These properties are passed as query parameters when embedding the player.
<!-- Customized Stream player with branded colors -->
<iframe
src="https://customer-ABCDE.cloudflarestream.com/abc123/iframe?skinColor=%23ff6600&
primaryColor=%23ff6600&textColor=%23ffffff&controls=%5B%22play%22%2C%22fullscreen%22%5D"
style="border:none;width:640px;height:360px"
allow="accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture"
allowfullscreen>
</iframe>
The skin parameters above set the accent color to orange (#ff6600) and limit controls to play and fullscreen buttons. You can customize virtually every visual aspect of the player.
JavaScript Player API
For deeper integration, use the Stream player JavaScript SDK. It gives you programmatic control over playback, events, and state.
// Initialize the Stream player with JavaScript
const player = Stream(document.getElementById('my-player'), {
src: 'abc123',
autoplay: true,
controls: true,
muted: false,
});
// Control playback via API methods
player.play();
player.pause();
player.setCurrentTime(30); // Seek to 30 seconds
player.setVolume(0.8); // Set volume to 80%
// Expected: player starts at 30 seconds with 80% volume
The SDK exposes methods for play, pause, seek, volume control, quality selection, and fullscreen toggling. Every method returns the player instance for chaining.
Listening to Player Events
The player fires events throughout the playback lifecycle. You can listen to these events to trigger custom behavior like analytics tracking or UI updates.
// Track viewer engagement with Stream player events
const player = Stream(document.getElementById('my-player'), { src: 'abc123' });
player.addEventListener('play', () => {
console.log('Video started at', player.getCurrentTime());
// Expected: "Video started at 0"
});
player.addEventListener('timeupdate', () => {
const progress = (player.getCurrentTime() / player.getDuration()) * 100;
if (progress > 25 && !tracked25) {
sendAnalytics('watched_25_percent');
tracked25 = true;
}
// Expected: analytics event sent once at 25% progress
});
player.addEventListener('ended', () => {
sendAnalytics('video_completed');
showNextVideoSuggestion();
// Expected: analytics event sent on completion, next video shown
});
Common events include play, pause, timeupdate, ended, error, seeking, seeked, and fullscreenchange. Use these to build engagement tracking, advertising triggers, and custom overlays.
FAQ
Practice Questions
- How do you customize the accent color of the Cloudflare Stream player?
- What JavaScript API method seeks to a specific time in the Stream player?
- Which event would you listen to for tracking when a viewer finishes watching a video?
Summary
The Cloudflare Stream player offers deep customization through skin properties, a full JavaScript API, and a comprehensive event system. You can tailor the visual appearance, control playback programmatically, and track viewer behavior through event listeners. This makes it suitable for building branded video experiences, analytics integrations, and custom control interfaces.
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro -- security-first tools for the modern web.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro