Search code examples
videohtml5-videogoogle-vrwebvr360-degrees

Google VRView for Web - Detect when a 360° video finishes


My requirement is really simple: I need to load another 360° video with Google VRView for Web as soon as the current running video has ended.

There are 4 types of events described in the documentation but unfortunately no event to detect when the video finishes. I couldn't even find a property to disable the loop.

Has anybody been able to implement something like this?

var vrView = new VRView.Player('#vrview', {
    video: 'link/to/first-video.mp4',
    is_stereo: true
  });


// I couldn't find an event like this or another solution

vrView.on('end', function() {

  vrView.setContent({
    video: 'link/to/second-video.mp4',
    is_stereo: true
  });

});


Solution

  • Although the documentation shows 4 types of events, as you say, the source on GitHub seems to actually support and additional one for 'ended' (https://github.com/googlevr/vrview).

    You can see it defined in main.js and used in player.js:

    Player.prototype.onMessage_ = function(event) {
      var message = event.data;
      if (!message || !message.type) {
        console.warn('Received message with no type.');
        return;
      }
      var type = message.type.toLowerCase();
      var data = message.data;
    
      switch (type) {
        case 'ready':
        case 'modechange':
        case 'error':
        case 'click':
        case 'ended':
          if (type === 'ready') {
            if (data !== undefined) {
              this.duration = data.duration;
        }
          }