Maxime
Maxime

Reputation: 729

Youtube embedded video problem (video unavailable)

I've a got a problem when I'd like to embed a YouTube video on my expo application, when I click on the play button, I sometimes get this message :

unavaible_message_from_youtube

For example, when I posted this video on reddit, it played perfectly through their youtube embedded player.

I use this sample of code:

              <WebView
                useWebKit={true}
                ref={(ref) => { this.videoPlayer = ref;}}
                source={{uri: 'https://www.youtube.com/embed/bo_efYhYU2A?rel=0&autoplay=0&showinfo=0&controls=0'}}
                scrollEnabled={false}
                domStorageEnabled={true}
                javaScriptEnabled={true}
              />

I know for a fact that the video is allowed to be embedded because when it's not the case, I get a different error message which allows me to open the video on youtube : screenshot_disable_embedded

Here is a link to test it : https://snack.expo.io/@maxgfr/youtube-embedded

Any help would be greatly appreciated

Maxime

Edit : example of url which doesn't work https://www.youtube.com/embed/8GaWM2a3FAc

Upvotes: 2

Views: 7506

Answers (1)

Maxime
Maxime

Reputation: 729

To solve this problem :

I create a web application which loads a youtube video thanks to the video ID. My endpoint is something like that : https://mywebsite.com/ID_VIDEO_YOUTUBE

Then in my react native application, I just have to load the URL of my website :

<WebView
   useWebKit={true}
   ref={(ref) => { this.videoPlayer = ref;}}
   source={{uri: 'https://mywebsite.com/ID_VIDEO_YOUTUBE'}}
   scrollEnabled={false}
   domStorageEnabled={true}
   javaScriptEnabled={true}
/>

Edit : Here is the sample of code that I use in my Vue JS application

<template>
  <div style="position: fixed;overflow-y: hidden;overflow-x: hidden;width:100%;height:100%;">
    <iframe style="width:100%;height:100%;" :src="'https://www.youtube.com/embed/'+this.$route.params.id+'?&autoplay=1&playsinline=1'" autoplay="1" playsinline="1" frameborder="0" scrolling="no" allow="playsinline; accelerometer; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
  </div>
</template>

<script>
export default {
  name: 'youtube',
  head: {
    link: [{
      r: 'icon',
      h: '/static/favicon.png',
      t: 'image/png'
    }]
  }
}
</script>

Upvotes: 5

Related Questions