1.0.16 • Published 6 months ago

react-native-video-vlc v1.0.16

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

react-native-video-vlc

react-native-video-vlc is a React Native library that provides a native video component based on VLC, enabling smooth and customizable video playback in your React Native applications.


Features

  • Customizable video playback with support for multiple resize modes.
  • Audio and subtitle track selection.
  • Progress updates and event handling.
  • Native VLC capabilities for robust media handling.
  • Text track sideloading and delay support.

Installation

To install the library, run:

npm install react-native-video-vlc

Or with yarn:

yarn add react-native-video-vlc

Usage

Here is an example of how to use the VideoVLC component:

import { StyleSheet } from 'react-native';
import VideoVLC from 'react-native-video-vlc';

const App = () => {
  return (
    <VideoVLC
      style={styles.container}
      source={{ uri: 'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4' }}
      onProgress={(e) => console.log('Progress:', e)}
      onError={(e) => console.error('Error:', e)}
      onLoad={(e) => console.log('Video Loaded:', e)}
      onEnd={() => console.log('Video Ended')}
    />
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});
export default App;

Props

Main Props

PropTypeDefaultDescription
sourceReactVideoVLCSourcenullVideo source. Supports remote URLs or local files.
repeatbooleanfalseIf true, the video will loop indefinitely.
resizeModeEnumValues<VideoResizeMode>noneDefines how the video should be resized within its container.
pausedbooleanfalsePauses the video playback when true.
mutedbooleanfalseMutes the audio when true.
volumenumber100Sets the audio volume (0-100).
progressUpdateIntervalnumber250Interval (ms) for onProgress updates.
selectedTextTracknumbernullIndex of the selected text (subtitle) track.
selectedAudioTracknumbernullIndex of the selected audio track.
textTrackDelaynumber0Delay for text (subtitle) tracks in seconds.

Source Properties

PropertyTypeDefaultDescription
uristring | NodeRequirenullThe video source URI. Supports both remote and local sources.
minLoadRetryCountnumber0Minimum retry attempts for loading.
mediaOptionsstring[]nullVLC-specific media options.
headersHeaders{}HTTP headers for fetching the video. A record of key-value pairs where the key is the header name and the value is the header value. Example: { 'Authorization': 'Bearer token' }.
startPositionnumber0Start position of the video in seconds.
textTracksSideloadTrack[][]Array of subtitle tracks to sideload. See SideloadTrack for details.

SideloadTrack

PropertyTypeDescription
titlestringThe title of the subtitle track. Optional.
languagestringThe language code of the subtitle track (e.g., 'en', 'fr'). Optional.
uristringURI of the subtitle file to sideload. Required.

Events

EventCallback ParametersDescription
onEnd()Called when the video playback finishes.
onBufferOnBufferDataTriggered during buffering. Contains: { isBuffering: boolean }.
onErrorOnVideoErrorDataTriggered when an error occurs. Contains: { error: { errorString: string, errorCode: number } }.
onLoadOnLoadDataCalled when the video is loaded. Provides detailed information. See OnLoadData below.
onLoadStart()Triggered when the video starts loading.
onProgressOnProgressDataCalled at regular intervals with progress information (in seconds). Contains: { currentTime: number, seekableDuration: number, progress: number }.
onPlaybackStateChangedOnPlaybackStateChangedDataTriggered when playback state changes. Contains: { isPlaying: boolean, isSeeking: boolean }.

OnLoadData

The onLoad event provides the following data:

PropertyTypeDescription
currentTimenumberCurrent playback position (in seconds) when the video is loaded.
durationnumberTotal duration of the video (in seconds).
naturalSizeobjectContains the video's dimensions and orientation.
naturalSize.widthnumberWidth of the video in pixels.
naturalSize.heightnumberHeight of the video in pixels.
naturalSize.orientation'landscape', 'portrait', 'square'The video's orientation.
videoTracksArray<{ id: number, selected: boolean, title?: string, language?: string }>Details of available video tracks. Each track has an ID, selection state, title (optional), and language (optional).
audioTracksArray<{ id: number, selected: boolean, title?: string, language?: string }>Details of available audio tracks. Each track has an ID, selection state, title (optional), and language (optional).
textTracksArray<{ id: number, selected: boolean, title?: string, language?: string }>Details of available text (subtitle) tracks. Each track has an ID, selection state, title (optional), and language (optional).

Enums

VideoResizeMode

  • none: Default mode.
  • cover: Scale the video uniformly to cover the container.
  • stretch: Stretch the video to fill the container.
  • original: Display the video in its original size.
  • 16:9, 16:10, 4:3, 5:4, 2.35:1, 2.21:1, 2.39:1: Aspect ratio presets.

Ref Methods

The VideoVLC component exposes the following methods via a ref:

MethodParametersDescription
seektime: numberSeeks the video to the specified time (in seconds).

To use the ref methods, you can follow this example:

import React, { useRef } from 'react';
import { StyleSheet, View, Button } from 'react-native';
import VideoVLC from 'react-native-video-vlc';

const App = () => {
  const videoRef = useRef(null);

  const handleSeek = () => {
    if (videoRef.current) {
      videoRef.current.seek(30); // Seek to 30 seconds
    }
  };

  return (
    <View style={styles.container}>
      <VideoVLC
        style={styles.video}
        ref={videoRef}
        source={{ uri: 'https://example.com/video.mp4' }}
        resizeMode="cover"
      />
      <Button title="Seek to 30s" onPress={handleSeek} />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#000',
  },
  video: {
    width: '100%',
    height: 300
  }
});

export default App;

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests on GitHub.


License

react-native-video-vlc is released under the MIT License. See LICENSE for details.

1.0.16

6 months ago

1.0.15

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago