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 Apr 29, 2024
2 parents b92954a + 1a8295c commit 2019395
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 34 deletions.
7 changes: 2 additions & 5 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ body:
attributes:
value: Thanks for taking the time to fill out this bug report!

- type: dropdown
- type: textarea
id: version
attributes:
label: Version
description: What version are you using?
options:
- v6 (Beta)
- v5 (Stable)
description: What version are you using? Put the exact version from your package.json
validations:
required: true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1642,31 +1642,31 @@ public void setSelectedTrack(int trackType, String type, String value) {
type = "default";
}

if (type.equals("disabled")) {
if ("disabled".equals(type)) {
disableTrack(rendererIndex);
return;
} else if (type.equals("language")) {
} else if ("language".equals(type)) {
for (int i = 0; i < groups.length; ++i) {
Format format = groups.get(i).getFormat(0);
if (format.language != null && format.language.equals(value)) {
groupIndex = i;
break;
}
}
} else if (type.equals("title")) {
} else if ("title".equals(type)) {
for (int i = 0; i < groups.length; ++i) {
Format format = groups.get(i).getFormat(0);
if (format.id != null && format.id.equals(value)) {
groupIndex = i;
break;
}
}
} else if (type.equals("index")) {
} else if ("index".equals(type)) {
int iValue = Integer.parseInt(value);
if (iValue < groups.length) {
groupIndex = iValue;
}
} else if (type.equals("resolution")) {
} else if ("resolution".equals(type)) {
int height = Integer.parseInt(value);
for (int i = 0; i < groups.length; ++i) { // Search for the exact height
TrackGroup group = groups.get(i);
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/component/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ Payload:
| ----------- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| currentTime | number | Time in seconds where the media will start |
| duration | number | Length of the media in seconds |
| naturalSize | object | Properties:<br/> _ width - Width in pixels that the video was encoded at<br/> _ height - Height in pixels that the video was encoded at<br/> \* orientation - "portrait" or "landscape" |
| naturalSize | object | Properties:<br/> _ width - Width in pixels that the video was encoded at<br/> _ height - Height in pixels that the video was encoded at<br/> \* orientation - "portrait", "landscape" or "square" |
| audioTracks | array | An array of audio track info objects with the following properties:<br/> _ index - Index number<br/> _ title - Description of the track<br/> _ language - 2 letter [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) or 3 letter [ISO639-2](https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes) language code<br/> _ type - Mime type of track |
| textTracks | array | An array of text track info objects with the following properties:<br/> _ index - Index number<br/> _ title - Description of the track<br/> _ language - 2 letter [ISO 639-1](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes) or 3 letter [ISO 639-2](https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes) language code<br/> _ type - Mime type of track |
| videoTracks | array | An array of video track info objects with the following properties:<br/> _ trackId - ID for the track<br/> _ bitrate - Bit rate in bits per second<br/> _ codecs - Comma separated list of codecs<br/> _ height - Height of the video<br/> \* width - Width of the video |
Expand Down
28 changes: 21 additions & 7 deletions examples/basic/src/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,13 @@ class VideoPlayer extends Component {

srcAllPlatformList = [
{
description: 'local file',
description: 'local file landscape',
uri: require('./broadchurch.mp4'),
},
{
description: 'local file portrait',
uri: require('./portrait.mp4'),
},
{
description: '(hls|live) red bull tv',
uri: 'https://rbmn-live.akamaized.net/hls/live/590964/BoRB-AT/master_928.m3u8',
Expand All @@ -133,6 +137,11 @@ class VideoPlayer extends Component {
description: 'sintel with subtitles',
uri: 'https://bitmovin-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
},
{
description: 'sintel starts at 20sec',
uri: 'https://bitmovin-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
startPosition: 50000,
},
{
description: 'BigBugBunny sideLoaded subtitles',
// sideloaded subtitles wont work for streaming like HLS on ios
Expand Down Expand Up @@ -360,7 +369,9 @@ class VideoPlayer extends Component {
};

onEnd = () => {
this.channelUp();
if (!this.state.loop) {
this.channelUp();
}
};

onPlaybackRateChange = (data: OnPlaybackRateChangeData) => {
Expand Down Expand Up @@ -593,21 +604,21 @@ class VideoPlayer extends Component {

renderTopControl() {
return (
<>
<Text style={[styles.controlOption]}>
<View style={styles.topControlsContainer}>
<Text style={styles.controlOption}>
{this.srcList[this.state.srcListId]?.description || 'local file'}
</Text>
<View>
<TouchableOpacity
onPress={() => {
this.toggleControls();
}}>
<Text style={[styles.leftRightControlOption]}>
<Text style={styles.leftRightControlOption}>
{this.state.showRNVControls ? 'Hide controls' : 'Show controls'}
</Text>
</TouchableOpacity>
</View>
</>
</View>
);
}

Expand Down Expand Up @@ -1032,6 +1043,9 @@ const styles = StyleSheet.create({
width: 100,
height: 40,
},
});
topControlsContainer: {
paddingTop: 30,
}
});

export default VideoPlayer;
Binary file added examples/basic/src/portrait.mp4
Binary file not shown.
28 changes: 12 additions & 16 deletions ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1281,33 +1281,29 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
guard let _playerItem else { return }
var duration = Float(CMTimeGetSeconds(_playerItem.asset.duration))

if duration.isNaN {
duration = 0.0
if duration.isNaN || duration == 0 {
// This is a safety check for live video.
// AVPlayer report a 0 duration
duration = RCTVideoUtils.calculateSeekableDuration(_player).floatValue
if duration.isNaN {
duration = 0
}
}

var width: Float?
var height: Float?
var width: Float = 0
var height: Float = 0
var orientation = "undefined"

Task {
let tracks = await RCTVideoAssetsUtils.getTracks(asset: _playerItem.asset, withMediaType: .video)
if let videoTrack = tracks?.first {
width = Float(videoTrack.naturalSize.width)
height = Float(videoTrack.naturalSize.height)
let preferredTransform = videoTrack.preferredTransform

if (videoTrack.naturalSize.width == preferredTransform.tx
&& videoTrack.naturalSize.height == preferredTransform.ty)
|| (preferredTransform.tx == 0 && preferredTransform.ty == 0) {
orientation = "landscape"
} else {
orientation = "portrait"
}
} else if _playerItem.presentationSize.height != 0.0 {
width = Float(_playerItem.presentationSize.width)
height = Float(_playerItem.presentationSize.height)
orientation = _playerItem.presentationSize.width > _playerItem.presentationSize.height ? "landscape" : "portrait"
}
orientation = width > height ? "landscape" : width == height ? "square" : "portrait"

if self._pendingSeek {
self.setSeek([
Expand Down Expand Up @@ -1337,8 +1333,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
"canStepBackward": NSNumber(value: _playerItem.canStepBackward),
"canStepForward": NSNumber(value: _playerItem.canStepForward),
"naturalSize": [
"width": width != nil ? NSNumber(value: width!) : "undefinded",
"height": width != nil ? NSNumber(value: height!) : "undefinded",
"width": width,
"height": height,
"orientation": orientation,
],
"audioTracks": audioTracks,
Expand Down

0 comments on commit 2019395

Please sign in to comment.