Getting Started
Installation
Section titled âInstallationânpm install @capgo/capacitor-jw-playernpx cap syncyarn add @capgo/capacitor-jw-playernpx cap syncpnpm add @capgo/capacitor-jw-playernpx cap syncbun add @capgo/capacitor-jw-playernpx cap syncPrerequisites
Section titled âPrerequisitesâYouâll need a JW Player account and license key to use this plugin. Sign up at JW Player if you donât have one.
Platform Configuration
Section titled âPlatform ConfigurationâAdd your JW Player license key to your Info.plist:
<key>JWPlayerLicenseKey</key><string>YOUR_LICENSE_KEY</string>Android
Section titled âAndroidâAdd your JW Player license key to android/app/src/main/res/values/strings.xml:
<resources> <string name="jw_player_license_key">YOUR_LICENSE_KEY</string></resources>Usage Example
Section titled âUsage Exampleâimport { JWPlayer } from '@capgo/capacitor-jw-player';
// Play a single videoawait JWPlayer.playVideo({ mediaUrl: 'https://example.com/video.mp4', title: 'My Video', description: 'Video description', poster: 'https://example.com/poster.jpg'});
// Play a playlistawait JWPlayer.playPlaylist({ playlistUrl: 'https://example.com/playlist.json'});
// Listen for player eventsJWPlayer.addListener('playerReady', () => { console.log('Player is ready');});
JWPlayer.addListener('play', (data) => { console.log('Video started playing');});
JWPlayer.addListener('pause', (data) => { console.log('Video paused');});
JWPlayer.addListener('complete', (data) => { console.log('Video playback completed');});
JWPlayer.addListener('error', (error) => { console.error('Player error:', error);});API Reference
Section titled âAPI ReferenceâplayVideo(options)
Section titled âplayVideo(options)âplayVideo(options: VideoOptions) => Promise<void>Play a single video in fullscreen mode.
| Param | Type |
|---|---|
options | VideoOptions |
playPlaylist(options)
Section titled âplayPlaylist(options)âplayPlaylist(options: PlaylistOptions) => Promise<void>Play a playlist in fullscreen mode.
| Param | Type |
|---|---|
options | PlaylistOptions |
pause()
Section titled âpause()âpause() => Promise<void>Pause the current video.
play() => Promise<void>Resume video playback.
seek(options)
Section titled âseek(options)âseek(options: { position: number }) => Promise<void>Seek to a specific position in the video.
| Param | Type |
|---|---|
options | { position: number } |
setPlaybackSpeed(options)
Section titled âsetPlaybackSpeed(options)âsetPlaybackSpeed(options: { speed: number }) => Promise<void>Set the playback speed.
| Param | Type |
|---|---|
options | { speed: number } |
setVolume(options)
Section titled âsetVolume(options)âsetVolume(options: { volume: number }) => Promise<void>Set the audio volume (0.0 to 1.0).
| Param | Type |
|---|---|
options | { volume: number } |
selectAudioTrack(options)
Section titled âselectAudioTrack(options)âselectAudioTrack(options: { trackIndex: number }) => Promise<void>Select an audio track by index.
| Param | Type |
|---|---|
options | { trackIndex: number } |
selectCaptionTrack(options)
Section titled âselectCaptionTrack(options)âselectCaptionTrack(options: { trackIndex: number }) => Promise<void>Select a caption/subtitle track by index.
| Param | Type |
|---|---|
options | { trackIndex: number } |
stop() => Promise<void>Stop playback and close the player.
Interfaces
Section titled âInterfacesâVideoOptions
Section titled âVideoOptionsâ| Prop | Type | Description |
|---|---|---|
mediaUrl | string | URL of the video file |
title | string | Video title (optional) |
description | string | Video description (optional) |
poster | string | URL of the poster/thumbnail (optional) |
autoStart | boolean | Auto-start playback (optional, default: true) |
PlaylistOptions
Section titled âPlaylistOptionsâ| Prop | Type | Description |
|---|---|---|
playlistUrl | string | URL of the JW playlist JSON |
autoStart | boolean | Auto-start playback (optional) |
Event Listeners
Section titled âEvent ListenersâAvailable Events
Section titled âAvailable EventsâplayerReady- Player is initialized and readyplay- Video playback startedpause- Video playback pausedcomplete- Video playback completederror- Player encountered an errorseek- User sought to a different positiontime- Playback time updatedbufferChange- Buffer state changed
Event Example
Section titled âEvent Exampleâ// Listen for time updatesJWPlayer.addListener('time', (data) => { console.log('Current time:', data.position); console.log('Duration:', data.duration);});
// Listen for buffer changesJWPlayer.addListener('bufferChange', (data) => { console.log('Buffering:', data.buffering);});
// Remove listener when doneconst listener = await JWPlayer.addListener('play', (data) => { console.log('Playing');});
// Later...listener.remove();Advanced Usage
Section titled âAdvanced UsageâPlaying with Captions
Section titled âPlaying with Captionsâawait JWPlayer.playVideo({ mediaUrl: 'https://example.com/video.mp4', title: 'Video with Subtitles', poster: 'https://example.com/poster.jpg', tracks: [ { file: 'https://example.com/captions-en.vtt', label: 'English', kind: 'captions' }, { file: 'https://example.com/captions-es.vtt', label: 'Spanish', kind: 'captions' } ]});Custom Playback Controls
Section titled âCustom Playback Controlsâimport { JWPlayer } from '@capgo/capacitor-jw-player';
// Start playingawait JWPlayer.play();
// Pause after 10 secondssetTimeout(() => { JWPlayer.pause();}, 10000);
// Seek to 30 secondsawait JWPlayer.seek({ position: 30 });
// Set playback speed to 1.5xawait JWPlayer.setPlaybackSpeed({ speed: 1.5 });
// Set volume to 50%await JWPlayer.setVolume({ volume: 0.5 });Best Practices
Section titled âBest Practicesâ- Always provide a poster image for better user experience
- Handle player errors gracefully with appropriate error messages
- Clean up event listeners when component unmounts
- Test video playback on both iOS and Android devices
- Use appropriate video formats (MP4 recommended)
- Implement loading states while video initializes
- Consider network conditions when streaming
Troubleshooting
Section titled âTroubleshootingâVideo Wonât Play
Section titled âVideo Wonât Playâ- Verify your JW Player license key is correct
- Check that video URL is accessible and valid
- Ensure proper CORS headers if using custom server
- Test with different video formats
Fullscreen Issues
Section titled âFullscreen Issuesâ- The plugin always plays in fullscreen mode
- Ensure proper permissions for fullscreen in your app
Performance
Section titled âPerformanceâ- Use appropriate video quality for target devices
- Consider adaptive streaming for better performance
- Implement proper buffering indicators