TheWidlarzGroup / react-native-video

A <Video /> component for react-native
https://docs.thewidlarzgroup.com/react-native-video/
MIT License
7.2k stars 2.9k forks source link

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

Closed wack17s closed 2 years ago

wack17s commented 7 years ago

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

gergob commented 7 years ago

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

xavieramoros commented 7 years ago

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 commented 7 years ago

RN 0.40, RN Video 1.0.0

kevinvandijk commented 7 years ago

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

alixeb commented 7 years ago

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 commented 7 years ago

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

mcatmos commented 7 years ago

Not working on Android

452MJ commented 7 years ago

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 commented 7 years ago

Any update on this?

alvelig commented 7 years ago

Same for me... not working on Android.

Choujiji commented 7 years ago

+1 hope to fix it

heartAndRain commented 7 years ago

This function seems not to be implemented in java

alixeb commented 7 years ago

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 commented 7 years ago

@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 commented 7 years ago

Any update with this?

RyanMitchellWilson commented 7 years ago

Any update?

b-asaf commented 7 years ago

same here, I am using RN 0.45.1 video 1.2.0

presentFullscreenPlayer() is not working on Android.

mandriv commented 7 years ago

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

leon3110l commented 7 years ago

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 commented 7 years ago

Would be good to have an official answer on this

viperfx commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

Do you have reference code for the default player or exoplayer?

Also does exoplayer currently support full screen?

On Sep 13, 2017 18:37, "Andrew Jack" notifications@github.com wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/react-native-community/react-native-video/issues/534#issuecomment-329316753, or mute the thread https://github.com/notifications/unsubscribe-auth/AAUCQeTFDenDojENDcaJhV96ol-D3Wsqks5siFkjgaJpZM4Mg7xP .

alvelig commented 7 years ago

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

viperfx commented 7 years ago

@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 commented 7 years ago

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 commented 6 years ago

@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 commented 6 years ago

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

landmass commented 6 years ago

@wack17s How is the problem resolved ?

Noitidart commented 6 years ago

Still open @landmass - eagerly awaiting a solution.

It would be awesome to get native players for non-fullscreen too in this module.

Niu-12138 commented 6 years ago

not working

ben-snaize commented 6 years ago

Not working, so instead I implemented a modal version for Android that sets to 100% width - I don't need the video controls. Not the best but better than nothing!

kashsbd commented 6 years ago

How about this package.

https://www.npmjs.com/package/react-native-af-video-player

drpiou commented 6 years ago

same here

khanhtdbse commented 6 years ago

Still waiting for this implementation 😢

drpiou commented 6 years ago

So I came up doing my own fullscreen player and it is working great. Go on your own guys, it will be implemented sooner this way ;)

mrarronz commented 6 years ago

Hey guys, check out this example: https://github.com/mrarronz/react-native-blog-examples/tree/master/Chapter7-VideoPlayer/VideoExample, maybe this is what you want.

See the related blog here: https://juejin.im/post/5a9f9fde518825557207e7b0.

b-asaf commented 6 years ago

Did any one knows how to modify the code in JAVA? or can reference me to a good tutorial? All the workarounds are nice, but its just too much code that can go wrong at some point

jayasme commented 6 years ago

This repository hasn't been updated for more than 1 year!!!!!!! It's necessary to care about remove the repo from the react-native community

haziqhafizuddin commented 6 years ago

any update?

kyle-ssg commented 6 years ago

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.

ScreamZ commented 6 years ago

For those who keep struggling : https://github.com/ScreamZ/react-native-true-sight

cobarx commented 6 years ago

I've implemented basic fullscreen support for ExoPlayer where it will hide the nav bar and status bar appropriately. It will take some additional work to have some kind of fullscreen style so you don't have to measure the height & width.

I can probably copy that code over to the Android player as well.

I'll take a deeper look at this sometime this week.

Noitidart commented 6 years ago

Thank you @cobarx that would be so cool!

xstable commented 6 years ago

@kyle-ssg Where do you get rnVideoPlayer from? And how do you toggle this fullScreen-Property of ?

xstable commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

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

chengsam commented 6 years ago

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.