Getting Started
Ce contenu n'est pas encore disponible dans votre langue.
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()
Section titled “play()”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()
Section titled “stop()”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