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

this.player.presentFullscreenPlayer() doesn't work on android #534

Closed
wack17s opened this issue Mar 17, 2017 · 73 comments
Closed

this.player.presentFullscreenPlayer() doesn't work on android #534

wack17s opened this issue Mar 17, 2017 · 73 comments
Assignees
Labels
stale Closed due to inactivity or lack or resources

Comments

@wack17s
Copy link

wack17s commented Mar 17, 2017

hi, button with this.player.presentFullscreenPlayer() handler do nothing on android, ios works good. Any suggestions?

@gergob
Copy link

gergob commented Mar 18, 2017

Please share more details, like version of the react-native-video component and a code snippet would be good too @wack17s

@xavieramoros
Copy link

I have the same problem.

My react-native-video component is wrapped within a InViewPort component to know if it's visible or not.

Something like:

<InViewPort key={'videoInViewPort'} onChange={this._onPlayerVisibilityChanged}>
	<View 
	key={'videoPlayer'}
	<Video 
		key={'video'}
		ref={(ref) => {
			this.player = ref
		}}
		playInBackground={false}
		paused={this.state.paused} 
		style={{flex: 1}}
		resizeMode={"cover"}
		muted={this.state.muted}
		source={{uri: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"}} 
	/> 
</View>
</InViewPort>

I use the reference to this.player to trigger fullscreen mode (this.player.presentFullscreenPlayer())

I'm using react-native 0.40 and react-native-video 1.0.0. I tested in Android 5.1.1 (Samsung Galaxy J5) and Android 6.0.1 (OnePlus 2 with Oxygen OS)

@wack17s
Copy link
Author

wack17s commented Mar 29, 2017

RN 0.40, RN Video 1.0.0

@kevinvandijk
Copy link

Can confirm. Tested with RN 0.43.1 with RN Video master on multiple Android devices. The presentFullscreenPlayer does not work on Android.

@alixeb
Copy link

alixeb commented Apr 26, 2017

This does not seem to be working on Windows either.
Also considering that presentFullscreenPlayer update the property fullscreen to be true.
Why cant we directly put fullscreen={true} or (false for that matter) directly on Video ?

@SebT
Copy link

SebT commented Apr 28, 2017

It does work on iOS but not android for me too.
RN 0.42, RN Video 1.0.0, android 6.

@mcatmos
Copy link

mcatmos commented May 5, 2017

Not working on Android

@452MJ
Copy link

452MJ commented May 7, 2017

Not working on Android. +1

"dependencies": {
"react": "16.0.0-alpha.6",
"react-native": "0.44.0",
"react-native-video": "^1.0.0",
"react-navigation": "^1.0.0-beta.9"
},

@roancoetzee
Copy link

Any update on this?

@alvelig
Copy link

alvelig commented May 27, 2017

Same for me... not working on Android.

@Choujiji
Copy link

+1 hope to fix it

@heartAndRain
Copy link

This function seems not to be implemented in java

@alixeb
Copy link

alixeb commented May 31, 2017

I don't know if this help, but the way I got around this is by using a dedicated route to play the video fullscreen.

So you can play the video fullscreen by:

  1. Use CSS to make video as big as the screen
  2. Use paused={false} to play the video by default
  3. Use paused={true} when the component unmount from the route change, as sometimes the sound keeps playing

You would need to have a custom Close/X button on the page to navigate away from to close the video

@SebT
Copy link

SebT commented May 31, 2017

@alixeb I use a similar technique that may help.

I have a reducer dedicated to the fullscreen video player and a component with a Video tag.

I put this component at the top level of my application (same level as my router) and connect it to the redux store.

Then I use redux actions to set the fullscreen video source and show/hide it based on a isActive prop.

Some code to help people implement it :

// FullscreenVideoPlayer/actions.js
import {createAction} from 'redux-actions';
import * as Constants from './constants';

export const initVideo = createAction(Constants.INIT_VIDEO);
export const resetVideo = createAction(Constants.RESET_VIDEO);
export const showVideo = createAction(Constants.SHOW_VIDEO);
export const hideVideo = createAction(Constants.HIDE_VIDEO);

// FullscreenVideoPlayer/reducer.js
import * as Constants from './constants';
import {handleActions} from 'redux-actions';

const INITIAL_STATE = {
  isActive: false,
  source: null
};

export default handleActions({

  [Constants.INIT_VIDEO]: (state, {payload}) => ({
    ...INITIAL_STATE,
    source: payload
  }),

  [Constants.SHOW_VIDEO]: (state, {payload}) => ({
    ...state,
    isActive: true
  }),

  [Constants.HIDE_VIDEO]: (state, {payload}) => ({
    ...state,
    isActive: false
  }),

  [Constants.RESET_VIDEO]: (state, {payload}) => ({
    ...INITIAL_STATE
  })
}, INITIAL_STATE);

// FullscreenVideoPlayer/index.js (no controls is this snippet but you can add it)
class FullscreenVideoPlayer extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      isLoading: true,
      translateY: new Animated.Value(windowHeight)
    };
  }

  componentWillReceiveProps(nextProps) {
    // Reset state when video changes (onLoad will be called and video will start)
    if (this.props.source !== nextProps.source) {
      this.setState({isLoading: true});
    }

    // Show / hide the fullscreen mode
    if (this.props.isActive !== nextProps.isActive) {
      Animated.timing(this.state.translateY, {
        toValue: nextProps.isActive ? 0 : windowHeight
      }).start(e => {
        // Play video on show
        if (nextProps.isActive) this.player.onStartPress();
      });
    }
  }

  render() {
    const {source, isActive} = this.props;
    const containerStyle = [
      styles.container,
      {transform: [
        {translateY: this.state.translateY}
      ]}
    ];
    return (
      <Animated.View style={containerStyle}>
        {isActive && <StatusBar hidden={true} />}
        {source && <VideoPlayer
          ref={n => this.player = n}
          video={{uri: source}}
          customStyles={{wrapper: styles.videoContainer, video: styles.video}}
          onLoad={this.handleVideoLoad.bind(this)}
          onEnd={this.handleVideoEnd.bind(this)}
          onRequestClose={this.handleVideoEnd.bind(this)}
        />}
      </Animated.View>
    );
  }

  /**
   * On video end, close fullscreen mode
   * @param e
   */
  handleVideoEnd(e) {
    this.props.hideVideo();
  }

  /**
   * On load, play video
   * @param e
   */
  handleVideoLoad(e) {
    this.setState({isLoading: false});
  }
}

const styles = StyleSheet.create({
  container: {
    ...StyleSheet.absoluteFillObject,
    flex: 1,
  },

  videoContainer: {
    flex: 1,
    transform: [
      {rotateZ: '90deg'},
      {translateY: ((PixelRatio.getPixelSizeForLayoutSize(windowHeight) - PixelRatio.getPixelSizeForLayoutSize(windowWidth)) / PixelRatio.get())},
    ],
    height: windowWidth,
    width: windowHeight,
    backgroundColor: 'black'
  },

  video: {
    height: windowWidth,
    alignSelf: "stretch"
  },
});

FullscreenVideoPlayer.propTypes = {
  source: PropTypes.string,
  isActive: PropTypes.bool,
  isPlaying: PropTypes.bool,
  isLoading: PropTypes.bool,
  playerProps: PropTypes.object
};

function select(state) {
  return state.fullscreenVideo;
}

export default connect(select, {hideVideo})(FullscreenVideoPlayer);

// App.js render
render() {
  return (
    <Provider store={store}>
      <View style={{flex: 1}}>
        <AppNavigator/>
        <FullscreenVideoPlayer/>
      </View>
    </Provider>
    );
}

Then just use the redux action to set the video src and active status.

@luisfuertes
Copy link

Any update with this?

@RyanMitchellWilson
Copy link

Any update?

@b-asaf
Copy link

b-asaf commented Aug 14, 2017

same here, I am using
RN 0.45.1
video 1.2.0

presentFullscreenPlayer() is not working on Android.

@mandriv
Copy link

mandriv commented Aug 27, 2017

Any info about whether this issue's going to be resolved?

@leon3110l
Copy link

I used the react-native-immersive package and StatusBar from react-native to hide the software buttons and the statusbar to make it fullscreen, hope this helps somebody.

@tirrorex
Copy link

tirrorex commented Sep 8, 2017

Would be good to have an official answer on this

@viperfx
Copy link

viperfx commented Sep 13, 2017

So I had a look at the Java code and I dont think fullscreen ever worked. There is no method in there that ties the JS bridge to a method to do anything for full screen mode.

@AndrewJack @isair seem to be common contributors to the Java code base. Maybe they can provider a more official answer.

@AndrewJack
Copy link
Contributor

I don't think it's implemented for Android.

You can achieve the same effect by making the video view fill up the whole screen, and hiding the status bar and software buttons

@viperfx
Copy link

viperfx commented Sep 14, 2017 via email

@alvelig
Copy link

alvelig commented Sep 14, 2017

@viperfx Maybe this can help https://medium.com/tall-programmer/fullscreen-functionality-with-android-exoplayer-5fddad45509f

@viperfx
Copy link

viperfx commented Sep 14, 2017

@alvelig I took a look but I am not that familiar with java to be able to implement it.

Ive found other resources too:
https://geoffledak.com/blog/2017/09/11/how-to-add-a-fullscreen-toggle-button-to-exoplayer-in-android/

Maybe it will help someone implement it.

@SebT would you be able to provide the implementation for the VideoPlayer component? I am finding that my source video does not rotate even with the transform applied.

@viperfx
Copy link

viperfx commented Sep 14, 2017

Ah nvm guys, I figured out a decent solution, similar to what you said @AndrewJack. The only downside I see, is a state change causes a re-render, and the video does not keep the same instance. So the video restarts. But its a small hitch.

@shouwangshe
Copy link

@SebT Hello! I'am trying play the video fullscreen on android, I looks your comment, I linsten the device's orientation'change and store up it in the state. Then I change the video'width and height from the device's orientation'state and I did't call anther component for the full-screen-video. My vedio still in the same component ; The problem is : When I press a button to full video screen It works;But then I change it back, the video don't play ,there's no picture; I guess if the video did't load or lose something,I'm still studying the RN; Maybe I just miss something basicly; or I did't get the method correctly; I hope to get some suggests; My English is Chinses English, Please understand,thanks;

@heiBin
Copy link

heiBin commented Dec 17, 2017

@shouwangshe 最后有没有解决全屏的问题?

@landmass
Copy link

@wack17s How is the problem resolved ?

@xstable
Copy link

xstable commented Jun 4, 2018

Found a solution:

add this to your package.json in section dependencies:

  "dependencies": {
.....
 "react-native-video": "tranvinhtruong/react-native-video",
  "react-native-video-player": "https://github.com/tranvinhtruong/react-native-video-player",
...
}

Then go an follow the Instruction on this Page: https://github.com/tranvinhtruong/react-native-video-player#setting-up-fullscreen-on-android

This makes FullScreen work for me on Android.

@johnlim5847
Copy link

@xstable Hi! can you elaborate or share your code? I've follow the guide but still not able to achieve the full screen on android

@brunoti
Copy link

brunoti commented Jul 17, 2018

Any news on this issue? How can we help? I really need this... @xstable solution only works partially (doesn't have a close button on FullScreen).

@b-asaf
Copy link

b-asaf commented Jul 17, 2018

Hi,
Is this issue solve in the new version of the package?

@chengsam
Copy link

Hi all, if you don't need to implement your own video player and want to display an intent chooser for the user to choose the video player, you can use https://github.com/BondGoat/react-native-native-video-player. I have tried and it worked on iOS and Android.

@MrHazimAli
Copy link

any update ?

@hermance
Copy link

Will this be in a future release? the lib is really great, this could be a very useful feature !
Thanks.

@ScreamZ
Copy link

ScreamZ commented Oct 26, 2018

@hermance @MrHazimAli No ad, but : https://github.com/ScreamZ/react-native-true-sight I made this when I struggled on that issue. This is using react-native-video but add a control layer on it.

@DavitVosk
Copy link

DavitVosk commented Dec 7, 2018

Any success with showing the video full screen on Android?

@wahdatkashmiri33
Copy link

`import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, Dimensions, StatusBar, Button } from 'react-native';
import Video from 'react-native-video';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons'
import { from } from 'rxjs';
export default class Main extends Component{

	state = {
	isPaused: false,
	//playName : 'pause-circle-filled',
	isMuted : false,

	isRotate : false,

	
};



render() {
	const { width } = Dimensions.get('window');
	const height = width * 0.5625;
	const nameplayIcon = 'pause-circle-filled'
	const namePauseIcon = 'play-arrow'
	let namePlay
	let pausedState = false
	
	
	if(pausedState === this.state.isPaused){
    namePlay = nameplayIcon;
	}
	else{
   namePlay = namePauseIcon
	}
	const unmuteIcon = 'volume-up'
	const muteIcon = 'volume-off'
	let nameMute 
	let mutedState = false
	if(mutedState === this.state.isMuted){
       nameMute = unmuteIcon

	}
	else{
		nameMute = muteIcon
	}

	const fullscreenIcon = 'fullscreen'
	const exitfullscreen = 'fullscreen-exit'
	let stateRotate = false
	let nameRotate
	if(stateRotate === this.state.isRotate){
		nameRotate = fullscreenIcon
	}
	else{
		nameRotate = exitfullscreen
		this.player.dismissFullscreenPlayer()
	}


	return (
		<View style={styles.container}>
			<Video
				source={require('../../demo_video.mp4')} // Can be a URL or a local file.
				ref={ref => {
					this.player = ref;
					
					
					
				}} // Store reference
				
				resizeMode="contain"
				onBuffer={this.onBuffer} // Callback when remote video is buffering
				onError={this.videoError} // Callback when video cannot be loaded
				style={{ width, height }}
				controls={true}
				paused={this.state.isPaused}
				muted = {this.state.isMuted}
				repeat = {true}
				
				
			  
			/>
			<View style = {{flex :1, flexDirection : 'row' , justifyContent : 'space-between'}} >
			<MaterialIcons name = {namePlay} onPress = {
				   
				   ()=> {this.setState((prevState) => {
				
						return {
							isPaused : !prevState.isPaused,
                            
							
						}
						
					})}
				
			} 
			//	
		
			size = {30} color="#900" />


          
             <View style = {{flex :1}} >
				<MaterialIcons name = {nameMute} 
				size = {30} 
				onPress = {
					() => {this.setState(
						(previous) => {
							return {
								isMuted :!previous.isMuted
							}
						}
					)}
				}
				/>
			</View>
		

			<View style = {{flex :1}} >
				<MaterialIcons name =  {nameRotate}
				size = {30} 
				onPress = {	()=>  
					{this.setState(
						(previousrotate) => {
							return {
						  isRotate : !previousrotate.isRotate,
						  
							}
						}
					),this.player.presentFullscreenPlayer()}
				}
				
				/>
			</View>
			</View>
				
		</View>
		
	);
}

}

const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'center',
backgroundColor: '#F5FCFF'
},
backgroundVideo: {
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0
}
});
`

@wahdatkashmiri33
Copy link

Above code works for me

@xstable
Copy link

xstable commented Feb 28, 2019

You might have a look at my repo.
I fork and upgraded react-native-video-player so that it now support react-native-video 4.4.0. Feel free to give it a try.

Because here, @IbrahimSulai is working on a build-in Fullscreen functionality, you can take my solution as temporary workaround

@hindkaer
Copy link

I've found that while this isn't implemented using react-native-video-player as a fallback for android and doing something like:

fullScreen = ()=> {
        if (Platform.OS == "android") {
            this.setState({paused: true})
            rnVideoPlayer.showVideoPlayer(this.props.source.uri);
        } else {
            this.player && this.player.presentFullscreenPlayer();
        }
    }

https://github.com/matiasfh/react-native-native-video-player#master

The code for launching the intent seems to be quite straight forward, not sure about keeping the current time though.

This solution worked for me, but the reference link is to a forked version which has an outdated README.

The original branch to react-native-native-video-player can be found here: https://github.com/BondGoat/react-native-native-video-player

@premillos
Copy link

any update?

@ahmetabdi
Copy link

How's this issue been going for more than two years? Android really is a second class citizen in react-native world

@Eramirez06
Copy link

Any update with this guys?

@earlyCloud
Copy link

Any update guys ? I use react-native-video version 4.4.4, and seems that I'm still face this issue. It's bit of frustration.

@irvin373
Copy link

irvin373 commented Dec 5, 2019

I handle in a native way using React Method and import in react
Android code:

@ReactMethod
    public void showVideoPlayer(String url) {
        Activity currentActivity = getCurrentActivity();
        if (currentActivity != null) {
            Intent videoIntent = new Intent(Intent.ACTION_VIEW);
            videoIntent.setDataAndType(Uri.parse(url), "video/*");
            currentActivity.startActivityForResult(videoIntent, VIDEO_CODE);
        }
    }

    @Override
    public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
        if (requestCode == VIDEO_CODE) {
            getCurrentActivity().finish();
        }
    }

React:

import {  Platform, NativeModules } from 'react-native';
const { VideoPlayerManager } = NativeModules;

displayVideo (url: string) {
    if (Platform.OS === 'android') {
      VideoPlayerManager.showVideoPlayer(url);
    } else if (this.player && this.shouldPlay) {
      this.shouldPlay = false;
      this.player.presentFullscreenPlayer();
    }
  }

Is just a patch while this issue is still open

@rivailruiz
Copy link

Any update?

@kvharini
Copy link

@irvin373
How to implement workaround for android? Can you give example in a project?

@DaniloPootaren
Copy link

Hello ,
Any updates on this issue?

@thecao-nucleusstudio
Copy link

@irvin373 Can you give me some more detail on your solution?

@irvin373
Copy link

@thecao-nucleusstudio I add a post https://medium.com/@irvin373/react-native-fullscreen-player-ac68925c53cc with all the code that you need :) and a very small example in github.

@hueniverse hueniverse added the stale Closed due to inactivity or lack or resources label Apr 22, 2022
@premillos

This comment was marked as spam.

@omarbakr2020
Copy link

Any new updates regarding this issue ?

@premillos

This comment was marked as spam.

@sen46Sko
Copy link

Just adding controll props for android platform solved my problem....

image

@premillos
Copy link

premillos commented May 28, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Closed due to inactivity or lack or resources
Projects
None yet
Development

No branches or pull requests