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

[RNMobile] Simple View for video view on Android #16136

Closed
Changes from all commits
Commits
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
30 changes: 30 additions & 0 deletions packages/block-library/src/video/video-play-button.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* WordPress dependencies
*/
import { Dashicon } from '@wordpress/components';

/**
* External dependencies
*/
import { View, TouchableOpacity } from 'react-native';

/**
* Internal dependencies
*/
import styles from './video-player.scss';

export default ( props ) => {
const { isSelected, onPressPlay, style } = props;

return (
<TouchableOpacity disabled={ ! isSelected } onPress={ onPressPlay } style={ [ style, styles.overlay ] }>
<View style={ styles.playIcon }>
<Dashicon
icon={ 'controls-play' }
ariaPressed={ 'dashicon-active' }
size={ styles.playIcon.width }
/>
</View>
</TouchableOpacity>
);
}
63 changes: 63 additions & 0 deletions packages/block-library/src/video/video-player.android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* WordPress dependencies
*/
import { Component } from '@wordpress/element';
import { Dashicon } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

/**
* External dependencies
*/
import { View, Linking, Alert } from 'react-native';

/**
* Internal dependencies
*/
import { default as VideoPlayButton } from './video-play-button';
import styles from './video-player.scss';

class Video extends Component {
constructor() {
super( ...arguments );
this.onPressPlay = this.onPressPlay.bind( this );
}

onPressPlay() {
const { source } = this.props;
if ( source && source.uri ) {
this.openURL( source.uri );
}
}

// Tries opening the URL outside of the app
openURL( url ) {
Linking.canOpenURL( url ).then( ( supported ) => {
if ( ! supported ) {
Alert.alert( __( 'Problem opening the video' ), __( 'No application can handle this request. Please install a Web browser.' ) );
window.console.warn( 'No application found that can open the video with URL: ' + url );
} else {
return Linking.openURL( url );
}
} ).catch( ( err ) => {
Alert.alert( __( 'Problem opening the video' ), __( 'An unknown error occurred. Please try again.' ) );
window.console.error( 'An error occurred while opening the video URL: ' + url, err );
} );
}

render() {
const { isSelected, style } = this.props;

return (
<View style={ styles.videoContainer }>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Gutenberg Web, there is an option to set a poster for the video. Probably we can use that prop this.props.attributes.poster and pass it here to show it as <ImageBackground> so that users can see the poster instead of black view?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, that seems to be part of the extra block settings functionality though, to manually set a poster image. I can be wrong but, it doesn't seem useable for our case where we want to have a preview picture automatically shown, based on a frame from the video.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Poster setting opened for public usage pretty recently, so I expect only a tiny amount of videos would come with a poster if any :(

<View { ...this.props } />
<VideoPlayButton
style={ style }
isSelected={ isSelected }
onPressPlay={ this.onPressPlay }
/>
</View>
);
}
}

export default Video;
Original file line number Diff line number Diff line change
@@ -8,18 +8,18 @@ import { __ } from '@wordpress/i18n';
/**
* External dependencies
*/
import { View, TouchableOpacity, Platform, Linking, Alert } from 'react-native';
import { View } from 'react-native';
import { default as VideoPlayer } from 'react-native-video';

/**
* Internal dependencies
*/
import { default as VideoPlayButton } from './video-play-button';
import styles from './video-player.scss';

class Video extends Component {
constructor() {
super( ...arguments );
this.isIOS = Platform.OS === 'ios';
this.state = {
isFullScreen: false,
videoContainerHeight: 0,
@@ -36,33 +36,11 @@ class Video extends Component {
}

onPressPlay() {
if ( this.isIOS ) {
if ( this.player ) {
this.player.presentFullscreenPlayer();
}
} else {
const { source } = this.props;
if ( source && source.uri ) {
this.openURL( source.uri );
}
if ( this.player ) {
this.player.presentFullscreenPlayer();
}
}

// Tries opening the URL outside of the app
openURL( url ) {
Linking.canOpenURL( url ).then( ( supported ) => {
if ( ! supported ) {
Alert.alert( __( 'Problem opening the video' ), __( 'No application can handle this request. Please install a Web browser.' ) );
window.console.warn( 'No application found that can open the video with URL: ' + url );
} else {
return Linking.openURL( url );
}
} ).catch( ( err ) => {
Alert.alert( __( 'Problem opening the video' ), __( 'An unknown error occurred. Please try again.' ) );
window.console.error( 'An error occurred while opening the video URL: ' + url, err );
} );
}

render() {
const { isSelected, style } = this.props;
const { isFullScreen, videoContainerHeight } = this.state;
@@ -92,11 +70,11 @@ class Video extends Component {
{ showPlayButton &&
// If we add the play icon as a subview to VideoPlayer then react-native-video decides to show control buttons
// even if we set controls={ false }, so we are adding our play button as a sibling overlay view.
<TouchableOpacity disabled={ ! isSelected } onPress={ this.onPressPlay } style={ [ style, styles.overlay ] }>
<View style={ styles.playIcon }>
<Dashicon icon={ 'controls-play' } ariaPressed={ 'dashicon-active' } size={ styles.playIcon.width } />
</View>
</TouchableOpacity>
<VideoPlayButton
style={ style }
isSelected={ isSelected }
onPressPlay={ this.onPressPlay }
/>
}
</View>
);