mob/admin/verb/volumetest()
var/script={"
<!-- 1. The <div> tag will contain the <iframe> (and video player) -->
<div id="player"></div>
<script> // 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName(\'script\')\[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
playerVars: { 'autoplay': 1, 'controls': 1,'autohide':1,'wmode':'opaque' },
videoId: 'JW5meKfy3fY',
events: {
'onReady': onPlayerReady}
});
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.mute();
}
</script>
"}
src << browse({"[script]"})
Problem description:
Javascript code from: http://jsfiddle.net/9RjzU/3/, for the YouTube Javascript API
This code works fine in a webserver, but the problems happen when you try it in a BYOND environment. The video simply does not load.
I inspected the youtube API help site and found this snippet:
From the Youtube API FAQ: https://developers.google.com/youtube/ js_api_reference#Playback_controls
"Note: To test any of these calls, you must have your file running on a webserver, as the Flash player restricts calls between local files and the internet."
This is probably what's causing my problems. So therefore, I need to store the javascript code on the internet instead of directly in BYOND. That causes a problem for my proc though because it would work, but only for that one specific video. I need a way to give the proc a video tag and pass that onto the script.
I have only taken java classes and am nowhere near as efficient with javascript, and I can't find anything else on this, so I have no idea where to even begin with this.
Any help would be much appreciated.
For example, you could send them to http://www.example.com/player.html#JW5meKfy3fY.
Then you could retrieve the ID in your javascript from the location.hash property:
var videoId = location.hash.substring(1); // Get ID from url fragment, and trim off the '#'
You could also append a GET query to the URL (parameters after a question mark) and parse that from location.search.