Skip to content

Commit

Permalink
feat: implement onAudioTracks and onTextTracks on ios
Browse files Browse the repository at this point in the history
  • Loading branch information
olivier committed Jan 28, 2024
1 parent 2094dbd commit 63a4fac
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/pages/component/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This page shows the list of available callbacks to handle player notifications
|-------------------------------------------------------------------------------------------------|---------------------------|
| [onAudioBecomingNoisy](#onaudiobecomingnoisy) | Android, iOS |
| [onAudioFocusChanged](#onaudiofocuschanged) | Android |
| [onAudioTracks](#onaudiotracks) | Android |
| [onAudioTracks](#onaudiotracks) | Android, iOS |
| [onBandwidthUpdate](#onbandwidthupdate) | Android |
| [onBuffer](#onbuffer) | Android, iOS |
| [onEnd](#onend) | All |
Expand All @@ -27,7 +27,7 @@ This page shows the list of available callbacks to handle player notifications
| [onRestoreUserInterfaceForPictureInPictureStop](#onrestoreuserinterfaceforpictureinpicturestop) | iOS, visionOS |
| [onSeek](#onseek) | All |
| [onTimedMetadata](#ontimedmetadata) | Android, iOS, visionOS |
| [onTextTracks](#ontexttracks) | Android |
| [onTextTracks](#ontexttracks) | Android, iOS |
| [onVideoTracks](#onvideotracks) | Android |
| [onVolumeChange](#onvolumechange) | Android, iOS, visionOS |

Expand Down
21 changes: 21 additions & 0 deletions ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
@objc var onRestoreUserInterfaceForPictureInPictureStop: RCTDirectEventBlock?
@objc var onGetLicense: RCTDirectEventBlock?
@objc var onReceiveAdEvent: RCTDirectEventBlock?
@objc var onTextTracks: RCTDirectEventBlock?
@objc var onAudioTracks: RCTDirectEventBlock?

@objc
func _onPictureInPictureStatusChanged() {
Expand Down Expand Up @@ -246,6 +248,19 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}
}

/// Tracks notifications is handled here.
override func observeValue(forKeyPath keyPath: String?,

Check failure on line 252 in ios/Video/RCTVideo.swift

View workflow job for this annotation

GitHub Actions / Swift-Lint

Block Based KVO Violation: Prefer the new block based KVO API with keypaths when using Swift 3.2 or later (block_based_kvo)
of object: Any?,
change: [NSKeyValueChangeKey : Any]?,

Check failure on line 254 in ios/Video/RCTVideo.swift

View workflow job for this annotation

GitHub Actions / Swift-Lint

Colon Spacing Violation: Colons should be next to the identifier when specifying a type and next to the key in dictionary literals (colon)
context: UnsafeMutableRawPointer?) {
if keyPath == #keyPath(AVPlayerItem.tracks) {
all(RCTVideoUtils.getAudioTrackInfo(self._player), RCTVideoUtils.getTextTrackInfo(self._player)).then { audioTracks, textTracks in
self.onTextTracks?(["textTracks": textTracks])
self.onAudioTracks?(["audioTracks": audioTracks])
}
}
}

// MARK: - Progress

func sendProgressUpdate() {
Expand Down Expand Up @@ -363,6 +378,12 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH

self._player = self._player ?? AVPlayer()
self._player?.replaceCurrentItem(with: playerItem)

// observe tracks update
self._player?.currentItem?.addObserver(self,
forKeyPath: #keyPath(AVPlayerItem.tracks),

Check failure on line 384 in ios/Video/RCTVideo.swift

View workflow job for this annotation

GitHub Actions / Swift-Lint

Vertical Parameter Alignment on Call Violation: Function parameters should be aligned vertically if they're in multiple lines in a method call (vertical_parameter_alignment_on_call)
options: [.old, .new],

Check failure on line 385 in ios/Video/RCTVideo.swift

View workflow job for this annotation

GitHub Actions / Swift-Lint

Vertical Parameter Alignment on Call Violation: Function parameters should be aligned vertically if they're in multiple lines in a method call (vertical_parameter_alignment_on_call)
context: nil)

Check failure on line 386 in ios/Video/RCTVideo.swift

View workflow job for this annotation

GitHub Actions / Swift-Lint

Vertical Parameter Alignment on Call Violation: Function parameters should be aligned vertically if they're in multiple lines in a method call (vertical_parameter_alignment_on_call)
self._playerObserver.player = self._player
self.applyModifiers()
self._player?.actionAtItemEnd = .none
Expand Down
2 changes: 2 additions & 0 deletions ios/Video/RCTVideoManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ @interface RCT_EXTERN_MODULE (RCTVideoManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(onPictureInPictureStatusChanged, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onRestoreUserInterfaceForPictureInPictureStop, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onReceiveAdEvent, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onTextTracks, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onAudioTracks, RCTDirectEventBlock);

RCT_EXTERN_METHOD(save
: (NSDictionary*)options reactTag
Expand Down

0 comments on commit 63a4fac

Please sign in to comment.