Commencer
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 Compte and Licence 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>Utilisation Exemple
Section titled “Utilisation Exemple”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 Référence
Section titled “API Référence”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 } |
Arrêter()
Section titled “Arrêter()”stop() => Promise<void>Arrêter 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”Disponible Events
Section titled “Disponible 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 Exemple
Section titled “Event Exemple”// 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 Utilisation
Section titled “Advanced Utilisation”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 Utilisateur experience
- Handle player errors gracefully with appropriate Erreur messages
- Clean up event listeners when component unmounts
- Test video playback on both iOS and Android Appareils
- Use appropriate video formats (MP4 recommended)
- Implement loading states while video initializes
- Consider network conditions when streaming
Dépannage
Section titled “Dépannage”Video Won’t Play
Section titled “Video Won’t Play”- Verify your JW Player Licence key is correct
- Vérifier 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 Application
Performance
Section titled “Performance”- Use appropriate video quality for target Appareils
- Consider adaptive streaming for better performance
- Implement proper buffering indicators