feat(android): add subtitle event (#3566)
* feat: add onCues method to get access to subtitle content
This commit is contained in:
parent
90b31af2c9
commit
6184c10acc
@ -59,6 +59,8 @@ public class VideoEventEmitter {
|
|||||||
private static final String EVENT_VOLUME_CHANGE = "onVolumeChange";
|
private static final String EVENT_VOLUME_CHANGE = "onVolumeChange";
|
||||||
private static final String EVENT_AUDIO_TRACKS = "onAudioTracks";
|
private static final String EVENT_AUDIO_TRACKS = "onAudioTracks";
|
||||||
private static final String EVENT_TEXT_TRACKS = "onTextTracks";
|
private static final String EVENT_TEXT_TRACKS = "onTextTracks";
|
||||||
|
|
||||||
|
private static final String EVENT_TEXT_TRACK_DATA_CHANGED = "onTextTrackDataChanged";
|
||||||
private static final String EVENT_VIDEO_TRACKS = "onVideoTracks";
|
private static final String EVENT_VIDEO_TRACKS = "onVideoTracks";
|
||||||
private static final String EVENT_ON_RECEIVE_AD_EVENT = "onReceiveAdEvent";
|
private static final String EVENT_ON_RECEIVE_AD_EVENT = "onReceiveAdEvent";
|
||||||
|
|
||||||
@ -86,6 +88,7 @@ public class VideoEventEmitter {
|
|||||||
EVENT_VOLUME_CHANGE,
|
EVENT_VOLUME_CHANGE,
|
||||||
EVENT_AUDIO_TRACKS,
|
EVENT_AUDIO_TRACKS,
|
||||||
EVENT_TEXT_TRACKS,
|
EVENT_TEXT_TRACKS,
|
||||||
|
EVENT_TEXT_TRACK_DATA_CHANGED,
|
||||||
EVENT_VIDEO_TRACKS,
|
EVENT_VIDEO_TRACKS,
|
||||||
EVENT_BANDWIDTH,
|
EVENT_BANDWIDTH,
|
||||||
EVENT_ON_RECEIVE_AD_EVENT
|
EVENT_ON_RECEIVE_AD_EVENT
|
||||||
@ -116,6 +119,7 @@ public class VideoEventEmitter {
|
|||||||
EVENT_VOLUME_CHANGE,
|
EVENT_VOLUME_CHANGE,
|
||||||
EVENT_AUDIO_TRACKS,
|
EVENT_AUDIO_TRACKS,
|
||||||
EVENT_TEXT_TRACKS,
|
EVENT_TEXT_TRACKS,
|
||||||
|
EVENT_TEXT_TRACK_DATA_CHANGED,
|
||||||
EVENT_VIDEO_TRACKS,
|
EVENT_VIDEO_TRACKS,
|
||||||
EVENT_BANDWIDTH,
|
EVENT_BANDWIDTH,
|
||||||
EVENT_ON_RECEIVE_AD_EVENT
|
EVENT_ON_RECEIVE_AD_EVENT
|
||||||
@ -144,6 +148,7 @@ public class VideoEventEmitter {
|
|||||||
private static final String EVENT_PROP_VIDEO_TRACKS = "videoTracks";
|
private static final String EVENT_PROP_VIDEO_TRACKS = "videoTracks";
|
||||||
private static final String EVENT_PROP_AUDIO_TRACKS = "audioTracks";
|
private static final String EVENT_PROP_AUDIO_TRACKS = "audioTracks";
|
||||||
private static final String EVENT_PROP_TEXT_TRACKS = "textTracks";
|
private static final String EVENT_PROP_TEXT_TRACKS = "textTracks";
|
||||||
|
private static final String EVENT_PROP_TEXT_TRACK_DATA = "subtitleTracks";
|
||||||
private static final String EVENT_PROP_HAS_AUDIO_FOCUS = "hasAudioFocus";
|
private static final String EVENT_PROP_HAS_AUDIO_FOCUS = "hasAudioFocus";
|
||||||
private static final String EVENT_PROP_IS_BUFFERING = "isBuffering";
|
private static final String EVENT_PROP_IS_BUFFERING = "isBuffering";
|
||||||
private static final String EVENT_PROP_PLAYBACK_RATE = "playbackRate";
|
private static final String EVENT_PROP_PLAYBACK_RATE = "playbackRate";
|
||||||
@ -284,6 +289,12 @@ public class VideoEventEmitter {
|
|||||||
receiveEvent(EVENT_TEXT_TRACKS, arrayToObject(EVENT_PROP_TEXT_TRACKS, textTracksToArray(textTracks)));
|
receiveEvent(EVENT_TEXT_TRACKS, arrayToObject(EVENT_PROP_TEXT_TRACKS, textTracksToArray(textTracks)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void textTrackDataChanged(String textTrackData){
|
||||||
|
WritableMap event = Arguments.createMap();
|
||||||
|
event.putString(EVENT_PROP_TEXT_TRACK_DATA, textTrackData);
|
||||||
|
receiveEvent(EVENT_TEXT_TRACK_DATA_CHANGED, event);
|
||||||
|
}
|
||||||
|
|
||||||
public void videoTracks(ArrayList<VideoTrack> videoTracks){
|
public void videoTracks(ArrayList<VideoTrack> videoTracks){
|
||||||
receiveEvent(EVENT_VIDEO_TRACKS, arrayToObject(EVENT_PROP_VIDEO_TRACKS, videoTracksToArray(videoTracks)));
|
receiveEvent(EVENT_VIDEO_TRACKS, arrayToObject(EVENT_PROP_VIDEO_TRACKS, videoTracksToArray(videoTracks)));
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ import androidx.media3.common.Timeline;
|
|||||||
import androidx.media3.common.TrackGroup;
|
import androidx.media3.common.TrackGroup;
|
||||||
import androidx.media3.common.TrackSelectionOverride;
|
import androidx.media3.common.TrackSelectionOverride;
|
||||||
import androidx.media3.common.Tracks;
|
import androidx.media3.common.Tracks;
|
||||||
|
import androidx.media3.common.text.CueGroup;
|
||||||
import androidx.media3.common.util.Util;
|
import androidx.media3.common.util.Util;
|
||||||
import androidx.media3.datasource.DataSource;
|
import androidx.media3.datasource.DataSource;
|
||||||
import androidx.media3.datasource.DataSpec;
|
import androidx.media3.datasource.DataSpec;
|
||||||
@ -1521,6 +1522,13 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
eventEmitter.timedMetadata(metadataArray);
|
eventEmitter.timedMetadata(metadataArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onCues(CueGroup cueGroup) {
|
||||||
|
if (!cueGroup.cues.isEmpty() && cueGroup.cues.get(0).text != null) {
|
||||||
|
String subtitleText = cueGroup.cues.get(0).text.toString();
|
||||||
|
eventEmitter.textTrackDataChanged(subtitleText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ReactExoplayerViewManager public api
|
// ReactExoplayerViewManager public api
|
||||||
|
|
||||||
public void setSrc(final Uri uri, final long startPositionMs, final long cropStartMs, final long cropEndMs, final String extension, Map<String, String> headers) {
|
public void setSrc(final Uri uri, final long startPositionMs, final long cropStartMs, final long cropEndMs, final String extension, Map<String, String> headers) {
|
||||||
|
@ -516,7 +516,7 @@ Example:
|
|||||||
|
|
||||||
### `onTextTrackDataChanged`
|
### `onTextTrackDataChanged`
|
||||||
|
|
||||||
<PlatformsList types={['iOS']} />
|
<PlatformsList types={['Android', 'iOS']} />
|
||||||
|
|
||||||
Callback function that is called when new subtitle data is available. It provides the actual subtitle content for the current selected text track, if available (mainly WebVTT).
|
Callback function that is called when new subtitle data is available. It provides the actual subtitle content for the current selected text track, if available (mainly WebVTT).
|
||||||
|
|
||||||
|
@ -120,15 +120,14 @@ class VideoPlayer extends Component {
|
|||||||
description: 'another bunny (can be saved)',
|
description: 'another bunny (can be saved)',
|
||||||
uri: 'https://rawgit.com/mediaelement/mediaelement-files/master/big_buck_bunny.mp4',
|
uri: 'https://rawgit.com/mediaelement/mediaelement-files/master/big_buck_bunny.mp4',
|
||||||
},
|
},
|
||||||
];
|
|
||||||
|
|
||||||
srcIosList = [
|
|
||||||
{
|
{
|
||||||
description: 'sintel with subtitles',
|
description: 'sintel with subtitles',
|
||||||
uri: 'https://bitmovin-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
|
uri: 'https://bitmovin-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
srcIosList = [];
|
||||||
|
|
||||||
srcAndroidList = [
|
srcAndroidList = [
|
||||||
{
|
{
|
||||||
description: 'Another live sample',
|
description: 'Another live sample',
|
||||||
|
Loading…
Reference in New Issue
Block a user