fix: implement lost presentFullscreenPlayer & dismissFullscreenPlayer

These apis has been removed during swift porting
This commit is contained in:
olivier 2023-09-04 23:57:45 +02:00
parent 0bf7f70e24
commit ddc87acf84
5 changed files with 66 additions and 3 deletions

4
API.md
View File

@ -551,10 +551,12 @@ Platforms: Android
#### fullscreen #### fullscreen
Controls whether the player enters fullscreen on play. Controls whether the player enters fullscreen on play.
See [presentFullscreenPlayer](#presentfullscreenplayer) for details.
* **false (default)** - Don't display the video in fullscreen * **false (default)** - Don't display the video in fullscreen
* **true** - Display the video in fullscreen * **true** - Display the video in fullscreen
Platforms: iOS Platforms: iOS, Android
#### fullscreenAutorotate #### fullscreenAutorotate
If a preferred [fullscreenOrientation](#fullscreenorientation) is set, causes the video to rotate to that orientation but permits rotation of the screen to orientation held by user. Defaults to TRUE. If a preferred [fullscreenOrientation](#fullscreenorientation) is set, causes the video to rotate to that orientation but permits rotation of the screen to orientation held by user. Defaults to TRUE.

View File

@ -40,6 +40,8 @@ class VideoPlayer extends Component {
this.onProgress = this.onProgress.bind(this); this.onProgress = this.onProgress.bind(this);
this.onBuffer = this.onBuffer.bind(this); this.onBuffer = this.onBuffer.bind(this);
} }
video = React.createRef();
state = { state = {
rate: 1, rate: 1,
volume: 1, volume: 1,
@ -155,6 +157,20 @@ class VideoPlayer extends Component {
) )
} }
renderFullscreenControl(fullscreen: string) {
return (
<TouchableOpacity onPress={() => {
if (fullscreen === 'fullscreen') {
this.video.presentFullscreenPlayer()
}
}}>
<Text style={[styles.controlOption]}>
{fullscreen}
</Text>
</TouchableOpacity>
)
}
renderMixWithOthersControl(mixWithOthers: string) { renderMixWithOthersControl(mixWithOthers: string) {
const isSelected = (this.state.mixWithOthers == mixWithOthers); const isSelected = (this.state.mixWithOthers == mixWithOthers);
@ -175,6 +191,9 @@ class VideoPlayer extends Component {
<View style={styles.container}> <View style={styles.container}>
<TouchableOpacity style={styles.fullScreen} onPress={() => {this.setState({paused: !this.state.paused})}}> <TouchableOpacity style={styles.fullScreen} onPress={() => {this.setState({paused: !this.state.paused})}}>
<Video <Video
ref={(ref: Video) => {
this.video = ref
}}
source={require('./broadchurch.mp4')} source={require('./broadchurch.mp4')}
style={styles.fullScreen} style={styles.fullScreen}
rate={this.state.rate} rate={this.state.rate}
@ -248,6 +267,9 @@ class VideoPlayer extends Component {
{this.renderMixWithOthersControl('mix')} {this.renderMixWithOthersControl('mix')}
{this.renderMixWithOthersControl('duck')} {this.renderMixWithOthersControl('duck')}
</View> </View>
<View style={styles.mixWithOthersControl}>
{this.renderFullscreenControl('fullscreen')}
</View>
</> : null </> : null
} }
</View> </View>

View File

@ -661,7 +661,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
func setFullscreen(_ fullscreen:Bool) { func setFullscreen(_ fullscreen:Bool) {
if fullscreen && !_fullscreenPlayerPresented && _player != nil { if fullscreen && !_fullscreenPlayerPresented && _player != nil {
// Ensure player view controller is not null // Ensure player view controller is not null
if _playerViewController == nil && _controls { // Controls will be displayed even if it is disabled in configuration
if _playerViewController == nil {
self.usePlayerViewController() self.usePlayerViewController()
} }
@ -691,7 +692,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
viewController.present(playerViewController, animated:true, completion:{ [weak self] in viewController.present(playerViewController, animated:true, completion:{ [weak self] in
guard let self = self else {return} guard let self = self else {return}
self._playerViewController?.showsPlaybackControls = self._controls // In fullscreen we must display controls
self._playerViewController?.showsPlaybackControls = true
self._fullscreenPlayerPresented = fullscreen self._fullscreenPlayerPresented = fullscreen
self._playerViewController?.autorotate = self._fullscreenAutorotate self._playerViewController?.autorotate = self._fullscreenAutorotate
@ -969,6 +971,14 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
_resouceLoaderDelegate?.setLicenseResultError(error) _resouceLoaderDelegate?.setLicenseResultError(error)
} }
func dismissFullscreenPlayer(_ error:String!) {
setFullscreen(false)
}
func presentFullscreenPlayer(_ error:String!) {
setFullscreen(true)
}
// MARK: - RCTPlayerObserverHandler // MARK: - RCTPlayerObserverHandler
func handleTimeUpdate(time:CMTime) { func handleTimeUpdate(time:CMTime) {

View File

@ -73,4 +73,10 @@ RCT_EXTERN_METHOD(setLicenseResult:(NSString *)license
RCT_EXTERN_METHOD(setLicenseResultError(NSString *)error RCT_EXTERN_METHOD(setLicenseResultError(NSString *)error
reactTag:(nonnull NSNumber *)reactTag) reactTag:(nonnull NSNumber *)reactTag)
RCT_EXTERN_METHOD(presentFullscreenPlayer
reactTag:(nonnull NSNumber *)reactTag)
RCT_EXTERN_METHOD(dismissFullscreenPlayer
reactTag:(nonnull NSNumber *)reactTag)
@end @end

View File

@ -48,6 +48,29 @@ class RCTVideoManager: RCTViewManager {
}) })
} }
@objc(dismissFullscreenPlayer:reactTag:)
func dismissFullscreenPlayer(error: NSString, reactTag: NSNumber) -> Void {
bridge.uiManager.prependUIBlock({_ , viewRegistry in
let view = viewRegistry?[reactTag]
if !(view is RCTVideo) {
RCTLogError("Invalid view returned from registry, expecting RCTVideo, got: %@", String(describing: view))
} else if let view = view as? RCTVideo {
view.dismissFullscreenPlayer(error as String)
}
})
}
@objc(presentFullscreenPlayer:reactTag:)
func presentFullscreenPlayer(error: NSString, reactTag: NSNumber) -> Void {
bridge.uiManager.prependUIBlock({_ , viewRegistry in
let view = viewRegistry?[reactTag]
if !(view is RCTVideo) {
RCTLogError("Invalid view returned from registry, expecting RCTVideo, got: %@", String(describing: view))
} else if let view = view as? RCTVideo {
view.presentFullscreenPlayer(error as String)
}
})
}
override func constantsToExport() -> [AnyHashable : Any]? { override func constantsToExport() -> [AnyHashable : Any]? {
return [ return [
"ScaleNone": AVLayerVideoGravity.resizeAspect, "ScaleNone": AVLayerVideoGravity.resizeAspect,