Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): allow chunckless preparation #3882

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
d3fc4fd
perf: ensure we do not provide callback to native if no callback prov…
freeboub May 5, 2024
e1da32d
chore: rework bufferConfig to make it more generic and reduce ReactEx…
freeboub May 6, 2024
df3da43
Merge branch 'master' of github.com:react-native-video/react-native-v…
freeboub May 8, 2024
0f33ad1
chore: improve issue template
freeboub May 8, 2024
17f2385
Merge branch 'TheWidlarzGroup:master' into master
freeboub May 10, 2024
1066898
fix(android): avoid video view flickering at playback startup
freeboub May 10, 2024
485f867
Merge branch 'master' of github.com:react-native-video/react-native-v…
freeboub May 11, 2024
a5e10a3
Merge branch 'master' of github.com:freeboub/react-native-video into …
freeboub May 11, 2024
9ce1d95
Merge branch 'master' of github.com:react-native-video/react-native-v…
freeboub May 15, 2024
fa27db7
Merge branch 'master' of github.com:react-native-video/react-native-v…
freeboub May 17, 2024
be681d3
Merge branch 'master' of github.com:react-native-video/react-native-v…
freeboub May 21, 2024
2fadb26
Merge branch 'master' of github.com:react-native-video/react-native-v…
freeboub May 23, 2024
92df10d
Merge branch 'master' of github.com:react-native-video/react-native-v…
freeboub May 24, 2024
aa61388
Merge branch 'master' of github.com:react-native-video/react-native-v…
freeboub May 28, 2024
ceafc53
Merge branch 'master' of github.com:react-native-video/react-native-v…
freeboub May 30, 2024
d30c5f5
Merge branch 'master' of github.com:react-native-video/react-native-v…
freeboub May 30, 2024
f3f8663
Merge branch 'master' of github.com:react-native-video/react-native-v…
freeboub Jun 3, 2024
5f8c461
Merge branch 'master' of github.com:react-native-video/react-native-v…
freeboub Jun 4, 2024
0eba6da
fix: ensure player doesn't start when view is unmounted
freeboub Jun 4, 2024
8693dbc
Fix/ensure view drop stop playback startup (#3875)
freeboub Jun 6, 2024
89c0e96
Merge branch 'master' of github.com:react-native-video/react-native-v…
freeboub Jun 7, 2024
77cb0e1
feat(android): add a way to disable chuncklessPreparation on HLS
freeboub Jun 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions android/src/main/java/com/brentvatne/common/api/Source.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.text.TextUtils
import com.brentvatne.common.toolbox.DebugLog
import com.brentvatne.common.toolbox.DebugLog.e
import com.brentvatne.common.toolbox.ReactBridgeUtils.safeGetArray
import com.brentvatne.common.toolbox.ReactBridgeUtils.safeGetBool
import com.brentvatne.common.toolbox.ReactBridgeUtils.safeGetInt
import com.brentvatne.common.toolbox.ReactBridgeUtils.safeGetMap
import com.brentvatne.common.toolbox.ReactBridgeUtils.safeGetString
Expand Down Expand Up @@ -44,6 +45,11 @@ class Source {
/** http header list */
val headers: MutableMap<String, String> = HashMap()

/** enable chunckless preparation for HLS
* see:
*/
var textTracksAllowChuncklessPreparation: Boolean = false

/** return true if this and src are equals */
override fun equals(other: Any?): Boolean {
if (other == null || other !is Source) return false
Expand Down Expand Up @@ -114,6 +120,7 @@ class Source {
private const val PROP_SRC_TYPE = "type"
private const val PROP_SRC_METADATA = "metadata"
private const val PROP_SRC_HEADERS = "requestHeaders"
private const val PROP_SRC_TEXT_TRACKS_ALLOW_CHUNCKLESS_PREPARATION = "textTracksAllowChunklessPreparation"

@SuppressLint("DiscouragedApi")
private fun getUriFromAssetId(context: Context, uriString: String): Uri? {
Expand Down Expand Up @@ -170,6 +177,7 @@ class Source {
source.cropStartMs = safeGetInt(src, PROP_SRC_CROP_START, -1)
source.cropEndMs = safeGetInt(src, PROP_SRC_CROP_END, -1)
source.extension = safeGetString(src, PROP_SRC_TYPE, null)
source.textTracksAllowChuncklessPreparation = safeGetBool(src, PROP_SRC_TEXT_TRACKS_ALLOW_CHUNCKLESS_PREPARATION, true)

val propSrcHeadersArray = safeGetArray(src, PROP_SRC_HEADERS)
if (propSrcHeadersArray != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ public class ReactExoplayerView extends FrameLayout implements
private long lastBufferDuration = -1;
private long lastDuration = -1;

private boolean viewHasDropped = false;
private void updateProgress() {
if (player != null) {
if (playerControlView != null && isPlayingAd() && controls) {
Expand Down Expand Up @@ -375,6 +376,8 @@ protected void onDetachedFromWindow() {
public void cleanUpResources() {
stopPlayback();
themedReactContext.removeLifecycleEventListener(this);
releasePlayer();
viewHasDropped = true;
}

//BandwidthMeter.EventListener implementation
Expand Down Expand Up @@ -647,6 +650,9 @@ private void initializePlayer() {
Activity activity = themedReactContext.getCurrentActivity();
// This ensures all props have been settled, to avoid async racing conditions.
mainRunnable = () -> {
if (viewHasDropped) {
return;
}
try {
if (player == null) {
// Initialize core configuration and listeners
Expand All @@ -658,7 +664,9 @@ private void initializePlayer() {
ExecutorService es = Executors.newSingleThreadExecutor();
es.execute(() -> {
// DRM initialization must run on a different thread

if (viewHasDropped) {
return;
}
if (activity == null) {
DebugLog.e(TAG, "Failed to initialize Player!, null activity");
eventEmitter.error("Failed to initialize Player!", new Exception("Current Activity is null!"), "1001");
Expand All @@ -667,12 +675,15 @@ private void initializePlayer() {

// Initialize handler to run on the main thread
activity.runOnUiThread(() -> {
if (viewHasDropped) {
return;
}
try {
// Source initialization must run on the main thread
initializePlayerSource();
} catch (Exception ex) {
self.playerNeedsSource = true;
DebugLog.e(TAG, "Failed to initialize Player!");
DebugLog.e(TAG, "Failed to initialize Player! 1");
DebugLog.e(TAG, ex.toString());
ex.printStackTrace();
self.eventEmitter.error(ex.toString(), ex, "1001");
Expand All @@ -684,7 +695,7 @@ private void initializePlayer() {
}
} catch (Exception ex) {
self.playerNeedsSource = true;
DebugLog.e(TAG, "Failed to initialize Player!");
DebugLog.e(TAG, "Failed to initialize Player! 2");
DebugLog.e(TAG, ex.toString());
ex.printStackTrace();
eventEmitter.error(ex.toString(), ex, "1001");
Expand Down Expand Up @@ -1033,7 +1044,7 @@ private MediaSource buildMediaSource(Uri uri, String overrideExtension, DrmSessi

mediaSourceFactory = new HlsMediaSource.Factory(
mediaDataSourceFactory
);
).setAllowChunklessPreparation(source.getTextTracksAllowChuncklessPreparation());
break;
case CONTENT_TYPE_OTHER:
if ("asset".equals(uri.getScheme())) {
Expand Down
17 changes: 16 additions & 1 deletion docs/pages/component/props.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ source={{ uri: 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8'

#### Overriding the metadata of a source

<PlatformsList types={['Android, iOS, tvOS']} />
<PlatformsList types={['Android', 'iOS', 'tvOS']} />

Provide an optional `title`, `subtitle`, `artist`, `imageUri` and/or `description` properties for the video.
Useful when using notification controls on Android or iOS or to adapt the tvOS playback experience.
Expand All @@ -773,6 +773,21 @@ source={{
}}
```

#### `textTracksAllowChunklessPreparation`
<PlatformsList types={['Android']} />

AllowChunklessPreparation for hls media source.
see: [disabling-chunkless](https://developer.android.com/media/media3/exoplayer/hls?#disabling-chunkless) in android documentation.

Default value: true.

```javascript
source={{
uri: 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
textTracksAllowChunklessPreparation: false,
}}
```

### `subtitleStyle`

| Property | Description | Platforms |
Expand Down
4 changes: 2 additions & 2 deletions ios/Video/NowPlayingInfoCenterManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class NowPlayingInfoCenterManager {
return
}

if let observer = observers[players.hashValue] {
if let observer = observers[player.hashValue] {
observer.invalidate()
}

observers.removeValue(forKey: players.hashValue)
observers.removeValue(forKey: player.hashValue)
players.remove(player)

if currentPlayer == player {
Expand Down
10 changes: 10 additions & 0 deletions ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1241,17 +1241,27 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
// MARK: - Lifecycle

override func removeFromSuperview() {
self._player?.replaceCurrentItem(with: nil)
if let player = _player {
player.pause()
NowPlayingInfoCenterManager.shared.removePlayer(player: player)
}
_playerItem = nil
_source = nil
_chapters = nil
_drm = nil
_textTracks = nil
_selectedTextTrackCriteria = nil
_selectedAudioTrackCriteria = nil
_presentingViewController = nil

_player = nil
_resouceLoaderDelegate = nil
_playerObserver.clearPlayer()

#if USE_GOOGLE_IMA
_imaAdsManager.releaseAds()
_imaAdsManager = nil
#endif

self.removePlayerLayer()
Expand Down
1 change: 1 addition & 0 deletions src/specs/VideoNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type VideoSrc = Readonly<{
cropStart?: Float;
cropEnd?: Float;
metadata?: VideoMetadata;
textTracksAllowChunklessPreparation?: boolean; // android
}>;

type DRMType = WithDefault<string, 'widevine'>;
Expand Down
1 change: 1 addition & 0 deletions src/types/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type ReactVideoSourceProperties = {
cropStart?: number;
cropEnd?: number;
metadata?: VideoMetadata;
textTracksAllowChunklessPreparation?: boolean;
};

export type ReactVideoSource = Readonly<
Expand Down
Loading