0

Vimeo method play() doesnt work and player object is undefined when I try to log it from console.

I am initializing vimeo player on my page like this:

<div id="myVideo"></div>    

var options = {
    url: "https://vimeo.com/showcase/xxxxxxx",
    width: window.innerWidth,
    height: window.innerHeight,
    autoplay: true,
    autopause: false,
    loop: true,
    muted: true,
    background: 1
};

var videoPlayer = new Vimeo.Player('myVideo', options);

then I am doing console log in my code

  $(document).ready(
  function(){  
    console.log(videoPlayer);
    videoPlayer.play(); 
 });

console.log(videoPlayer) works just fine here and prints object, but videoPlayer.play(); does nothing. When I am trying to do console.log(videoPlayer) from browser console I got Uncaught ReferenceError: videoPlayer is not defined. I am trying to start video directly from JS because autoplay doesnt work at all.

Player is initializing fine, but I have to press play button to start the video, but I need it to start automatically.

  • Can you share more of your code? The `play` method works just fine for me: https://codepen.io/JokerNN/pen/MWWyPBY . Also be sure that autoplay is enabled by user. Otherwise browser will just block the auto play – Andrey Oct 15 '19 at 12:11
  • [This one is also related.](https://stackoverflow.com/questions/49930680/how-to-handle-uncaught-in-promise-domexception-play-failed-because-the-use). Chrome will block the video if user didn't interact with the document first – Andrey Oct 15 '19 at 12:15
  • Well, thats all my code that relates to the video player. Is that possible that problem is with using showcase instead of just single video? However, as I said Player initializes fine, i can see whole playlist. – Игорь Быстревский Oct 15 '19 at 12:18
  • For player.js, you will need to provide a single video @ИгорьБыстревский – frobinsonj Oct 15 '19 at 12:22
  • 1
    What do I do if I need a lot of videos to be played as playlist? Create new player object for every single video? @frobinsonj – Игорь Быстревский Oct 15 '19 at 12:23
  • Instead, take a look at [embedding showcases](https://developer.vimeo.com/api/oembed/showcases#embedding-a-showcase-step-2) – frobinsonj Oct 15 '19 at 12:24
  • I'm afraid they don't support APIs like `play` for showcases: https://github.com/vimeo/player.js/issues/457 – Andrey Oct 15 '19 at 12:26
  • Possible duplicate of [Vimeo javascript api player.play() not playing](https://stackoverflow.com/questions/51001654/vimeo-javascript-api-player-play-not-playing) – weegee Oct 16 '19 at 08:26
  • There was no answer that would help me. Also in my question I am facing the problem that I cant access player object from browser console after page is loaded @weegee – Игорь Быстревский Oct 16 '19 at 08:40

2 Answers2

0

Try to init you variable inside document.ready function:

  $(document).ready(
  function(){  
    var videoPlayer = new Vimeo.Player('myVideo', options);
    videoPlayer.play(); 
 });
Guilherme Martin
  • 837
  • 1
  • 11
  • 22
0

Well, after all I just ended up using single videos and switching them through js. Show cases does not support many of features that can be used with single videos. I still cant access player object from console. But at least play() method is working now, since I am initializing it with video id instead of url

  var options = {
    id: xxxxxxxxx,
    width: window.innerWidth,
    height: window.innerHeight,
    muted: true,
};