Skip to content

Commit

Permalink
Merge branch 'master' of github.com:react-native-video/react-native-v…
Browse files Browse the repository at this point in the history
…ideo
  • Loading branch information
freeboub committed May 17, 2024
2 parents 9ce1d95 + d4c9be2 commit fa27db7
Show file tree
Hide file tree
Showing 10 changed files with 1,284 additions and 843 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# react-native-video
🎬 `<Video>` component for React Native

> **Note:** version 5.2.1 won't have any updates. We are currently working on making a 6.0.0 fully stable
## Documentation
documentation is available at [thewidlarzgroup.github.io/react-native-video/](https://thewidlarzgroup.github.io/react-native-video/)

Expand Down Expand Up @@ -61,4 +59,4 @@ We have an discord server where you can ask questions and get help. [Join the di
<source media="(prefers-color-scheme: light)" srcset="./docs/assets/baners/twg-light.png" />
<img alt="TheWidlarzGroup" src="./docs/assets/baners/twg-light.png" />
</picture>
</a>
</a>
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,12 @@ public void onCues(List<Cue> cues) {
@Override
public void onVideoSizeChanged(VideoSize videoSize) {
boolean isInitialRatio = layout.getAspectRatio() == 0;
layout.setAspectRatio(videoSize.height == 0 ? 1 : (videoSize.width * videoSize.pixelWidthHeightRatio) / videoSize.height);
if (videoSize.height == 0 || videoSize.width == 0) {
// When changing video track we receive an ghost state with height / width = 0
// No need to resize the view in that case
return;
}
layout.setAspectRatio((videoSize.width * videoSize.pixelWidthHeightRatio) / videoSize.height);

// React native workaround for measuring and layout on initial load.
if (isInitialRatio) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import androidx.media3.exoplayer.upstream.BandwidthMeter;
import androidx.media3.exoplayer.upstream.DefaultAllocator;
import androidx.media3.exoplayer.upstream.DefaultBandwidthMeter;
import androidx.media3.exoplayer.util.EventLogger;
import androidx.media3.extractor.metadata.emsg.EventMessage;
import androidx.media3.extractor.metadata.id3.Id3Frame;
import androidx.media3.extractor.metadata.id3.TextInformationFrame;
Expand Down Expand Up @@ -185,6 +186,11 @@ public class ReactExoplayerView extends FrameLayout implements
private ServiceConnection playbackServiceConnection;
private PlaybackServiceBinder playbackServiceBinder;

// logger to be enable by props
private EventLogger debugEventLogger = null;
private boolean enableDebug = false;
private static final String TAG_EVENT_LOGGER = "RNVExoplayer";

private int resumeWindow;
private long resumePosition;
private boolean loadVideoStarted;
Expand Down Expand Up @@ -508,6 +514,24 @@ private void reLayoutControls() {
reLayout(playerControlView);
}

public void setDebug(boolean enableDebug) {
this.enableDebug = enableDebug;
refreshDebugState();
}

private void refreshDebugState() {
if (player == null) {
return;
}
if (enableDebug) {
debugEventLogger = new EventLogger(TAG_EVENT_LOGGER);
player.addAnalyticsListener(debugEventLogger);
} else if (debugEventLogger != null) {
player.removeAnalyticsListener(debugEventLogger);
debugEventLogger = null;
}
}

private class RNVLoadControl extends DefaultLoadControl {
private final int availableHeapInBytes;
private final Runtime runtime;
Expand Down Expand Up @@ -666,6 +690,7 @@ private void initializePlayerCore(ReactExoplayerView self) {
.setLoadControl(loadControl)
.setMediaSourceFactory(mediaSourceFactory)
.build();
refreshDebugState();
player.addListener(self);
player.setVolume(muted ? 0.f : audioVolume * 1);
exoPlayerView.setPlayer(player);
Expand Down Expand Up @@ -712,6 +737,11 @@ private void initializePlayerSource(ReactExoplayerView self, DrmSessionManager d
.setLocalAdInsertionComponents(unusedAdTagUri -> adsLoader, exoPlayerView);
DataSpec adTagDataSpec = new DataSpec(adTagUrl);
mediaSourceWithAds = new AdsMediaSource(videoSource, adTagDataSpec, ImmutableList.of(srcUri, adTagUrl), mediaSourceFactory, adsLoader, exoPlayerView);
} else {
if (adTagUrl == null && adsLoader != null) {
adsLoader.release();
adsLoader = null;
}
}
MediaSource mediaSource;
if (mediaSourceList.size() == 0) {
Expand Down Expand Up @@ -745,11 +775,11 @@ private void initializePlayerSource(ReactExoplayerView self, DrmSessionManager d
boolean haveResumePosition = resumeWindow != C.INDEX_UNSET;
if (haveResumePosition) {
player.seekTo(resumeWindow, resumePosition);
}
if (startPositionMs >= 0) {
player.setMediaSource(mediaSource, false);
} else if (startPositionMs > 0) {
player.setMediaSource(mediaSource, startPositionMs);
} else {
player.setMediaSource(mediaSource, !haveResumePosition);
player.setMediaSource(mediaSource, true);
}
player.prepare();
playerNeedsSource = false;
Expand Down Expand Up @@ -1643,7 +1673,7 @@ public void onCues(CueGroup cueGroup) {

public void setSrc(final Uri uri, final long startPositionMs, final long cropStartMs, final long cropEndMs, final String extension, Map<String, String> headers, MediaMetadata customMetadata) {

if (this.customMetadata != customMetadata && player != null) {
if (!Util.areEqual(this.customMetadata, customMetadata) && player != null) {
MediaItem currentMediaItem = player.getCurrentMediaItem();

if (currentMediaItem != null) {
Expand Down Expand Up @@ -1677,8 +1707,10 @@ public void setSrc(final Uri uri, final long startPositionMs, final long cropSta

public void clearSrc() {
if (srcUri != null) {
player.stop();
player.clearMediaItems();
if (player != null) {
player.stop();
player.clearMediaItems();
}
this.srcUri = null;
this.startPositionMs = -1;
this.cropStartMs = -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ public void setDebug(final ReactExoplayerView videoView,
} else {
DebugLog.setConfig(Log.WARN, enableThreadDebug);
}
videoView.setDebug(enableDebug);
}

private boolean startsWithValidScheme(String uriString) {
Expand Down
Loading

0 comments on commit fa27db7

Please sign in to comment.