Results 1 to 1 of 1
  1. #1
    Desu Development
    Pomf pomf :3
    Fuck Sky's Avatar
    Join Date
    Sep 2013
    Location
    WOW ANIME MAN WOW
    Posts
    1,137
    Points
    1,687
         User Info     Contact     Gamer ID
    Join Date
    Sep 2013
    Location
    WOW ANIME MAN WOW
    Posts
    1,137
    Points
    1,687
    Gamer IDs

    Gamertag: Hexpresso PSN ID: WideDongWeary Steam ID: twitchhexpresso

    Contact info:

    Youtube Channel: http://www.youtube.com/ Kik Username: Wownicehack

    Default Synchronous YouTube Playback Concept

    Thought I'd talk about this since it's somewhat cool, in my opinion. And it's easy.

    Using YouTube's IFrame API, btw.

    This is starting assuming you've already figured out a way to get & store user input. I suggest Django + REST. Angular/Ember is nice as well.


    You need to request this url(replace id with video id and key with your key.)
    Code:
      var url = 'https://www.googleapis.com/youtube/v3/videos?id=' + id +
                    '&part=contentDetails&key=' + key;
    It'll return some straight forward data. One entry is the duration of the video in super autism format
    Something like this
    Code:
    PT4M22S
    Something like that. 4 = 4 minutes. 22 = 22 seconds. So just parse that out.

    Code:
    var parsedTime = response.items[0].contentDetails.duration.split('PT')[1];
    You can fetch minutes from that like so.
    Code:
    var obj = {};
    obj.minutes = parsedTime.split('M');
    Pass that object(after parsing seconds into it as well) to the next callback.

    Grats, you have the duration. Also make a check to make sure there's actually a seconds portion of the duration. Videos with a duration of *:59 will return *:00, but the API returns nothing. So be sure you only parse seconds if seconds are there.


    Now whenever someone adds a song, and a start_time equal to the last song's start_time + the duration of the last song. If there are no songs in queue, make the start_time current time. This should all be handled on the backend due to timezones.

    Then just listen for the time every second or so on the server side. If it hits the time, send out a broadcast telling all clients to launch the player with the new song's id. Or, you can do that on the client side if you don't like backend. But that's messy.



    Also can add auto-seek depending on if a client connects half-way thru a song. Pretty easy. Youtube's iframe api has a sleek auto-seek function built into it.


    Also disable controls so people can't fast forward. But then add these functions to buttons so people can control volume.

    Code:
        $scope.isMuted = false;
        function curVol() {
          return $scope.youtube.player.getVolume();
        }
    
        $scope.mute = function() {
          if (!$scope.isMuted) {
            $scope.isMuted = !$scope.isMuted;
            $scope.youtube.player.mute();
          }
        }
    
        $scope.unmute = function() {
          if ($scope.isMuted) {
            $scope.isMuted = !$scope.isMuted;
            $scope.youtube.player.unMute();
          }
        }
    
        $scope.volDown = function() {
          var newVol = curVol() - 10;
          $scope.youtube.player.setVolume(newVol);
        }
    
        $scope.volUp = function() {
          var newVol = curVol() + 10;
          $scope.youtube.player.setVolume(newVol);
        }

    Note: without auto-seek added your clients will only be synced within one video. And clients that join half way thru only get to see portions of the video, since eventually they'll receive a packet saying "launch player w/ new song". A solution would be to save each song's duration in minutes & seconds, then set each client on a timer using Angular's $interval function. Clients will only be synced within 1 video, but they will never hear a song half-way. Which can be nice.

    0 Not allowed! Not allowed!
    Last edited by Fuck Sky; 03-29-2016 at 10:04 AM.
    geadszf1231qewrg

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -10. The time now is 10:04 PM.
Powered by vBulletin®
Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.