Saltar al contenido

Comenzando

  1. Instalar el paquete

    Ventana de terminal
    npm i @Capgo/Capacitor-video-player
  2. Sincronizar con proyectos nativos

    Ventana de terminal
    npx cap sync
import { CapacitorVideoPlayer } from '@capgo/capacitor-video-player';
// Inicializar un reproductor de video
const playVideo = async () => {
const result = await CapacitorVideoPlayer.initPlayer({
mode: 'fullscreen',
url: 'https://example.com/video.mp4',
playerId: 'myPlayer',
componentTag: 'div'
});
console.log('Player initialized:', result);
};
// Reproducir el video
await CapacitorVideoPlayer.play({ playerId: 'myPlayer' });
// Pausar el video
await CapacitorVideoPlayer.pause({ playerId: 'myPlayer' });
// Obtener tiempo actual
const { value } = await CapacitorVideoPlayer.getCurrentTime({ playerId: 'myPlayer' });
console.log('Current time:', value);
// Buscar posición
await CapacitorVideoPlayer.setCurrentTime({
playerId: 'myPlayer',
seektime: 30 // segundos
});
// Establecer volumen (0-1)
await CapacitorVideoPlayer.setVolume({
playerId: 'myPlayer',
volume: 0.5
});

Inicializa una instancia del reproductor de video.

await CapacitorVideoPlayer.initPlayer({
mode: 'fullscreen', // o 'embedded'
url: 'https://example.com/video.mp4',
playerId: 'player1',
subtitle: 'https://example.com/subtitles.vtt',
language: 'en',
rate: 1.0,
exitOnEnd: true,
loopOnEnd: false,
pipEnabled: true,
showControls: true
});

Reproduce el video.

await CapacitorVideoPlayer.play({ playerId: 'player1' });

Pausa el video.

await CapacitorVideoPlayer.pause({ playerId: 'player1' });

Obtiene la duración del video en segundos.

const { value } = await CapacitorVideoPlayer.getDuration({ playerId: 'player1' });
console.log('Duration:', value, 'seconds');

Obtiene la posición de reproducción actual en segundos.

const { value } = await CapacitorVideoPlayer.getCurrentTime({ playerId: 'player1' });

Busca un tiempo específico.

await CapacitorVideoPlayer.setCurrentTime({
playerId: 'player1',
seektime: 60 // segundos
});

Establece el volumen (0.0 a 1.0).

await CapacitorVideoPlayer.setVolume({
playerId: 'player1',
volume: 0.8
});

Obtiene el volumen actual.

const { value } = await CapacitorVideoPlayer.getVolume({ playerId: 'player1' });

Silencia o activa el sonido del video.

await CapacitorVideoPlayer.setMuted({
playerId: 'player1',
muted: true
});

Establece la velocidad de reproducción.

await CapacitorVideoPlayer.setRate({
playerId: 'player1',
rate: 1.5 // velocidad 1.5x
});

Detiene todos los reproductores activos.

await CapacitorVideoPlayer.stopAllPlayers();

Sale del reproductor de video.

await CapacitorVideoPlayer.exitPlayer();
import { CapacitorVideoPlayer } from '@capgo/capacitor-video-player';
export class VideoPlayerService {
private playerId = 'mainPlayer';
async initializePlayer(videoUrl: string, subtitleUrl?: string) {
try {
const result = await CapacitorVideoPlayer.initPlayer({
mode: 'fullscreen',
url: videoUrl,
playerId: this.playerId,
subtitle: subtitleUrl,
language: 'en',
rate: 1.0,
exitOnEnd: true,
loopOnEnd: false,
pipEnabled: true,
bkmodeEnabled: true,
showControls: true,
displayMode: 'all'
});
console.log('Player initialized:', result);
return result;
} catch (error) {
console.error('Failed to initialize player:', error);
throw error;
}
}
async togglePlayPause() {
const { value: isPlaying } = await CapacitorVideoPlayer.isPlaying({
playerId: this.playerId
});
if (isPlaying) {
await CapacitorVideoPlayer.pause({ playerId: this.playerId });
} else {
await CapacitorVideoPlayer.play({ playerId: this.playerId });
}
}
async seekForward(seconds: number = 10) {
const { value: currentTime } = await CapacitorVideoPlayer.getCurrentTime({
playerId: this.playerId
});
await CapacitorVideoPlayer.setCurrentTime({
playerId: this.playerId,
seektime: currentTime + seconds
});
}
async seekBackward(seconds: number = 10) {
const { value: currentTime } = await CapacitorVideoPlayer.getCurrentTime({
playerId: this.playerId
});
await CapacitorVideoPlayer.setCurrentTime({
playerId: this.playerId,
seektime: Math.max(0, currentTime - seconds)
});
}
async setPlaybackSpeed(speed: number) {
await CapacitorVideoPlayer.setRate({
playerId: this.playerId,
rate: speed
});
}
async getProgress() {
const { value: currentTime } = await CapacitorVideoPlayer.getCurrentTime({
playerId: this.playerId
});
const { value: duration } = await CapacitorVideoPlayer.getDuration({
playerId: this.playerId
});
return {
currentTime,
duration,
percentage: (currentTime / duration) * 100
};
}
async cleanup() {
await CapacitorVideoPlayer.stopAllPlayers();
}
}
  • Requiere iOS 10.0+
  • Usa AVPlayer nativo
  • Soporta Picture-in-Picture
  • Reproducción en segundo plano soportada
  • Requiere Android 5.0 (API 21)+
  • Usa ExoPlayer
  • Soporta Chromecast
  • Colores de acento personalizados disponibles
  • Usa reproductor de video HTML5
  • Solo modo embebido
  • Características nativas limitadas
  1. Limpiar reproductores: Siempre detén los reproductores cuando termines
  2. Manejar errores: Envuelve llamadas del reproductor en try-catch
  3. IDs únicos de reproductor: Usa IDs únicos para múltiples reproductores
  4. Verificar estado de reproducción: Verifica el estado antes de operaciones
  5. Gestión de recursos: Libera reproductores para liberar memoria