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

Video don't play on android #3

Closed
arnaudambro opened this issue Mar 1, 2020 · 2 comments
Closed

Video don't play on android #3

arnaudambro opened this issue Mar 1, 2020 · 2 comments
Labels

Comments

@arnaudambro
Copy link

Hi there,

I have a great hope in your lib, as I need to play two videos in the same page and react-native-youtube doesn't do it for Android.

I installed very easily, it's working great on iOS, but on Android I can't play the video.

Here is my code :

import React from 'react'
import PropTypes from 'prop-types'
import YoutubePlayer from 'react-native-youtube-iframe'
import { withNavigationFocus } from 'react-navigation'
import { getImageSize } from '../utils/images'

const aspectRatio = 9 / 16
const imageSize = getImageSize(aspectRatio)

const Player = ({ videoID, onError, isFocused }) => {
  if (!isFocused) return null
  return (
    <YoutubePlayer
      height={imageSize.height}
      width={imageSize.width}
      videoId={videoID}
      onChangeState={(event) => console.log('Player onChangeState', event)}
      onReady={(e) => console.log('Player onReady', e)}
      onError={(e) => {
        console.log('Player error', e)
        onError(e)
      }}
      onPlaybackQualityChange={(q) => console.log('onPlaybackQualityChange', q)}
      volume={60}
      playbackRate={1}
      playerParams={{}}
    />
  )
}

Player.propTypes = {
  videoID: PropTypes.string.isRequired,
  onError: PropTypes.func,
  isFocused: PropTypes.bool.isRequired,
}
Player.defaultProps = {
  onError: () => null,
}

export default withNavigationFocus(Player)

When I click on the youtube button play, the log is the following:

 LOG  Player onChangeState unstarted
 LOG  Player onChangeState buffering
 LOG  onPlaybackQualityChange large
 LOG  Player onChangeState unstarted

Is there something I'm missing ?

@LonelyCpp
Copy link
Owner

Hi @arnaudambro , I'm glad you liked this library. Your issue seems to be related to autoplaying videos on android. Google doesn't allow this by default, so you must add some extra props to the player.

Add

webViewProps={{
          userAgent:
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
          mediaPlaybackRequiresUserAction: false,
        }}

to your <YoutubePlayer /> component and make sure you're on version 1.1.3

@arnaudambro
Copy link
Author

looks good ! thanks for being so quick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants