根据标签播放随机YouTube视频

Does anybody know a quick way for a script to play YouTube videos randomly by just entering in a tag from a web form? Trying to build it using PHP and JavaScript, wouldn't know where to begin using the YouTube API.

The setShuffle function instructs YouTube to play the videos in the playlist in random order (or to play them in their designated order.

player.setShuffle(shufflePlaylist:Boolean):Void

This function indicates whether a playlist's videos should be shuffled so that they play back in an order different from the one that the playlist creator designated. If you shuffle a playlist after it has already started playing, the list will be reordered while the video that is playing continues to play. The next video that plays will then be selected based on the reordered list.   This setting will not persist if you load or cue a different playlist, which means that if you load a playlist, call the setShuffle function, and then load a second playlist, the second playlist will not be shuffled.  

  • The required shufflePlaylist parameter indicates whether YouTube should shuffle the playlist.  
    • If the parameter value is true, then YouTube will shuffle the playlist order. If you instruct the function to shuffle a playlist that has already been shuffled, YouTube will shuffle the order again.  
    • If the parameter value is false, then YouTube will change the playlist order back to its original order.

click here to learn how to use YouTube JavaScript Player API Reference