Skip to content

Commit

Permalink
Stream might contain tracks which are not supported by platform. Add …
Browse files Browse the repository at this point in the history
…isSupported boolean to audio tracks.
  • Loading branch information
peeterkask committed Sep 13, 2024
1 parent e9e1446 commit 447b528
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions android/src/main/java/com/brentvatne/common/api/Track.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Track {
var mimeType: String? = null
var language: String? = null
var isSelected = false
var isSupported = true
var roleFlags: List<String> = emptyList()

// in bps available only on audio tracks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ class VideoEventEmitter {
if (format.bitrate > 0) putInt("bitrate", format.bitrate)
putBoolean("selected", format.isSelected)
putArray("roleFlags", roleFlagsToArray(format.roleFlags))
putBoolean("isSupported", format.isSupported)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1462,27 +1462,34 @@ private static boolean isTrackSelected(TrackSelection selection, TrackGroup grou

private ArrayList<Track> getAudioTrackInfo() {
ArrayList<Track> audioTracks = new ArrayList<>();
if (trackSelector == null) {
// Likely player is unmounting so no audio tracks are available anymore
return audioTracks;
}

MappingTrackSelector.MappedTrackInfo info = trackSelector.getCurrentMappedTrackInfo();
int index = getTrackRendererIndex(C.TRACK_TYPE_AUDIO);
if (info == null || index == C.INDEX_UNSET) {
return audioTracks;
if (player.isCommandAvailable(Player.COMMAND_GET_TRACKS)) {
Tracks currentTracks = player.getCurrentTracks();
for (Tracks.Group trackGroup : currentTracks.getGroups()) {
@C.TrackType int trackType = trackGroup.getType();

if (trackType == C.TRACK_TYPE_AUDIO) {
for (int i = 0; i < trackGroup.length; i++) {
boolean isSupported = trackGroup.isTrackSupported(i);
boolean isSelected = trackGroup.isTrackSelected(i);
Format trackFormat = trackGroup.getTrackFormat(i);

Track track = new Track();
track.setIndex(i);
if (trackFormat.sampleMimeType != null)
track.setMimeType(trackFormat.sampleMimeType);
if (trackFormat.language != null) track.setLanguage(trackFormat.language);
if (trackFormat.label != null) track.setTitle(trackFormat.label);
track.setSelected(isSelected);
track.setRoleFlags(Util.getRoleFlagStrings(trackFormat.roleFlags));
track.setSupported(isSupported);
track.setBitrate(trackFormat.bitrate == Format.NO_VALUE ? 0 : trackFormat.bitrate);
audioTracks.add(track);
}
}
}
}
TrackGroupArray groups = info.getTrackGroups(index);
TrackSelectionArray selectionArray = player.getCurrentTrackSelections();
TrackSelection selection = selectionArray.get( C.TRACK_TYPE_AUDIO );

for (int i = 0; i < groups.length; ++i) {
TrackGroup group = groups.get(i);
Format format = group.getFormat(0);
Track audioTrack = exoplayerTrackToGenericTrack(format, i, selection, group);
audioTrack.setBitrate(format.bitrate == Format.NO_VALUE ? 0 : format.bitrate);
audioTracks.add(audioTrack);
}
return audioTracks;
}

Expand Down
1 change: 1 addition & 0 deletions ios/Video/Features/RCTVideoUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ enum RCTVideoUtils {
"language": language ?? "",
"selected": currentOption?.displayName == selectedOption?.displayName,
"roleFlags": roleFlags,
"isSupported": true
] as [String: Any]
audioTracks.add(audioTrack)
}
Expand Down
1 change: 1 addition & 0 deletions src/specs/VideoNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ export type OnAudioTracksData = Readonly<{
type?: string;
selected?: boolean;
roleFlags: string[];
isSupported: boolean;
}[];
}>;

Expand Down
1 change: 1 addition & 0 deletions src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type OnLoadData = Readonly<{
type?: string;
selected?: boolean;
roleFlags: string[];
isSupported: boolean;
}[];
textTracks: {
index: number;
Expand Down

0 comments on commit 447b528

Please sign in to comment.