AfterGlowPlayer after setting dynamically data-youtube-id video won't play - javascript

I im using this video player:
http://docs.afterglowplayer.com/docs/playing-a-youtube-video
and after i dynamically add data-youtube-id i im unable to play video..do i need call with another way?
my script of reading glowplayer2 class and appending it to glowplayer3 class that can center glowplayer on the screen (glowplayer2 class is hidden div that contains php generated url)
$(".afterglowplayer2").click(function () {
switch(true) {
case /imdb/.test($("#myvideo video", this).attr("src")):
alert("IMDB!");
$(".afterglowplayer3 #myvideo video").attr("src", $("#myvideo video", this).attr("src"))
break;
default:
alert("YOUTUBE");
$(".afterglowplayer3 #myvideo video").attr("data-youtube-id", $("#myvideo video", this).attr("src")).removeAttr("src");
break;
}
$.afterglowplayer.toggle(".afterglowplayer3");
return false;
});
After that code i get this:
<video class="vjs-tech" id="myvideo_html5_api" data-ratio="0.5625" style="padding-top: 56.25%;" preload="auto" data-youtube-id="XpICoc65uh0"></video>
So you see that correct data-youtube-id is set using above jQuery function but video is not playing...why? If i set it manually in html code it plays normally...but i need to change and remove src if is youtube video and if is not add src attribute to video tag...

You should put their respective class (afterglow) and size
<video class="afterglow vjs-tech" width="960" height="540"...
edit Your code -> is misspelled.
$(".afterglowplayer2").click(function () {
if(/imdb/.test($("#uniqueid", this).attr("src")){
alert("IMDB!");
$("#uniqueid").attr("src", $("#uniqueid", this).attr("src"))
} else {
alert("YOUTUBE");
$("#uniqueid").attr("data-youtube-id", $("#uniqueid", this).attr("src")).removeAttr("src");
}
$.afterglowplayer.toggle(".afterglowplayer3");
return false;
});

Related

Embedded Vimeo Timestamp Link Not Working

I used to be able to get this to work where I press the link of the song, and it will jump to the time of the embedded Vimeo video in my site(Wordpress). The codes are as below:
HTML
<div class="wpb_video_widget wpb_content_element vc_clearfix vc_video-aspect-ratio-169 vc_video-el-width-100 vc_video-align-center">
<iframe id="player_1" src="https://player.vimeo.com/video/xxxxxxx?dnt=1&app_id=122963?api=1&player_id=player_1" width="1080" height="720" frameborder="0" allow="autoplay; fullscreen" allowfullscreen=""></iframe>
</div>
<div class="links">
<a class="link_1" href="javascript:void(0);" target="_self">Track 1 “Song Name”</a><br/>
<a class="link_2" href="javascript:void(0);" target="_self">Track 2 "Name of song"</a><br/>
JS Script
<script type="text/javascript">
// Set lesson times (in seconds)
var link_1_track = 000;
var link_2_track = 323;
// Function to hide all status messages
hidePlayNoticeAll = function() {
jQuery(".link_1_status").html("");
jQuery(".link_2_status").html("");
// Load Vimeo API for the embedded video
var iframe_player = jQuery('#player_1')[0];
var player_1 = $f(iframe_player);
// Function to control what happens when each lesson link is clicked
function setupLinks() {
jQuery(".link_1").click(function () {
player_1.api('play'); //Play the video
player_1.api('seekTo', link_1_track); //Seek to the number of seconds in the variable link_1_track
hidePlayNoticeAll(); // Hide all status messages before displaying (to prevent them from sticking)
jQuery(".link_1_status").html(playNotice); //Display status message (playNotice) within span with class link_1_status
});
jQuery(".link_2").click(function () {
player_1.api('play');
player_1.api('seekTo', link_2_track);
hidePlayNoticeAll();
jQuery(".link_2_status").html(playNotice);
});
}
setupLinks();
</script>
Is there anything wrong with the code? Or do I need an API from vimeo or jquery? I cant remember what I did to make it work before. Thank you in advance.
I have found the API that I needed to get this working. So I will be closing my own question haha.
The script made it worked like a charm, in case anyone wants to use the code, this is the script below. Cheers.
<script src="https://f.vimeocdn.com/js/froogaloop2.min.js"></script>

How detect in vanilia javascript end of video in tag <OBJECT> html?

I must use tag object type="video/mp4" in my project for hbbtv, and I want detect end of movie in vanilia JS. How can i do it?
document.getElementById('objectId').addEventListener('ended',endCallback,false);
function endCallback(e) {
//Action
}
When using the AVControl object, you have to register the PlayStateChange event and check playState 5 (Finished).
document.getElementById('objectId').onPlayStateChange = function() {
if (document.getElementById('objectId').playState == 5) { // FINISHED }
};
http://www.oipf.tv/docs/OIPF-T1-R2_Specification-Volume-5-Declarative-Application-Environment-v2_3-2014-01-24.pdf
7.14.1 The A/V Control object

Change youtube video on image on stop state

I made the code like this which changes an image on the web-site on Youtube video.
<script type="text/javascript">
$(window).load(function(){
$('img.demovideo').click(function(){
video = '<iframe class="demovideo" width="100%" height="551px" src="'+ $(this).attr('data-video') +'"></iframe>';
$(this).replaceWith(video);
});
$('img.demovideo').css('cursor', 'pointer');
});
</script>
How can I change the Youtube video back on image on player state 0?
I made a code like this, but it doesn't work:
<script type="text/javascript">
raketaplayer.onStateChange () {
b = raketaplayer.getPlayerState();
if (b=0) {
image = '<img class="demovideo" src="http://raketa.pro/wp-content/uploads/2013/03/image_header_2.png" data-video="http://www.youtube.com/embed/7hoqO36CVRM?&rel=0&theme=light&showinfo=0&hd=1&autohide=1&color=white&autoplay=1&enablejsapi=1&playerapiid=raketaplayer" style="cursor: pointer;">';
$(iframe.demovideo).replaceWith(image);
});
$('img.demovideo').css('cursor', 'pointer');
});
}
}
</script>
What's wrong with it? Please, help :)
Image code as follows:
<img class="demovideo" src="http://raketa.pro/wp-content/uploads/2013/03/image_header.png" data-video="http://www.youtube.com/embed/7hoqO36CVRM?&rel=0&theme=light&showinfo=0&hd=1&autohide=1&color=white&autoplay=1&enablejsapi=1&playerapiid=raketaplayer">
A couple of issues that you might want to address. First of all, your conditional statement uses a single equal sign instead of a double. More importantly, though, when you execute the onStateChange function, it can take an argument that represents the event, which will report the state change without you having to query for it, like this:
raketaplayer.onStateChange (event) {
if (event.data==0) {
image = '<img class="demovideo" src="http://raketa.pro/wp-content/uploads/2013/03/image_header_2.png" data-video="http://www.youtube.com/embed/7hoqO36CVRM?&rel=0&theme=light&showinfo=0&hd=1&autohide=1&color=white&autoplay=1&enablejsapi=1&playerapiid=raketaplayer" style="cursor: pointer;">';
$(iframe.demovideo).replaceWith(image);
});
$('img.demovideo').css('cursor', 'pointer');
});
}
}
Finally, make sure you've bound your onStateChange function to the state change event of the YT.Player object that you create elsewhere in your code.

how to play a swf background music on a website with javascript?

I want to play an swf file that contains sound only (so I can have background music on a website). I want to load that swf with javascript and not embeded it.
How do I do that?
I have found this code:
<embed
src="melodyloops-sounds-swf-player.swf"
width="25"
height="16"
allowscriptaccess="always"
allowfullscreen="false"
flashvars="filename=low-down.swf&volume=0&backcolor=ffffff&maincolor=00648C&timeplay=0"
/>
but I dont know how to make this swf play only when the function is called!
<script language="JavaScript">
function getFlashMovieObject(movieName)
{
if (window.document[movieName])
{
return window.document[movieName];
}
if (navigator.appName.indexOf("Microsoft Internet")==-1)
{
if (document.embeds && document.embeds[movieName])
return document.embeds[movieName];
}
else if (navigator.appName.indexOf("Microsoft Internet")!=-1)
{
return document.getElementById(movieName);
}
}
function PlayFlashMovie()
{
var flashMovie=getFlashMovieObject("PUT-YOUR-FLASH-ID-HERE");
flashMovie.Play();
var flashMovie=getFlashMovieObject("PUT-YOUR-FLASH-ID-HERE");
flashMovie.Play();
var flashMovie=getFlashMovieObject("PUT-YOUR-FLASH-ID-HERE");
flashMovie.Play();
}
</script>
Then make sure you have specified the names and id's for your flash elements so that the javascript can reference them. Pu an id="" field in the field, and the name="" in the tag.
I suggest you use use SWFObject which allows you to embed Flash on the fly when a javascript function is called:
http://code.google.com/p/swfobject/

Using jQuery to play/stop YouTube multiple iframe players

I am trying to play/stop multiple YouTube iframe players on a single page. I can start the players automatically (i.e. through a custom method called loadYouTubeVideo(playerID)) upon clicking, but I am not sure how I can get access to the player objects again from another function call (i.e. through a custom method called unloadYouTubeVideo(playerID))
Here is the jsfiddle with what I am talking about: http://jsfiddle.net/iwasrobbed/9Dj8c/3/
So each player starts, but it continues to play even after the div containing it is hidden.
By the way, I am using the iframe version of the player for a reason, so answers telling me to 'just use the flash object embed version' of the player are not acceptable for this question.
Code here in case jsfiddle is not available:
<html>
<body>
<script>
$(document).ready(function(){
// YouTube Player API adapter
$.getScript('http://www.youtube.com/player_api');
loadYouTubePlayer = function(playerID) {
the_player = new YT.Player(playerID, {
events: { 'onReady': playYouTubeVideo }
});
};
unloadYouTubePlayer = function(playerID) {
// This is the part that's broken
$(playerID).stopVideo();
};
function playYouTubeVideo(event) {
event.target.playVideo();
}
$('.show_player').click(function() {
var idType = 'data-video-id';
var id = $(this).attr(idType);
$(this).fadeOut('fast', function() {
$('.hidden_player['+idType+'='+id+']').fadeIn('fast', function() {
loadYouTubePlayer('the_player'+id);
$('.stop_player['+idType+'='+id+']').fadeIn('fast');
});
});
});
$('.stop_player').click(function() {
var idType = 'data-video-id';
var id = $(this).attr(idType);
$(this).fadeOut('fast', function() {
$('.hidden_player['+idType+'='+id+']').fadeOut('fast', function() {
unloadYouTubePlayer('the_player'+id);
$('.show_player['+idType+'='+id+']').fadeIn('fast');
});
});
});
});
</script>
<div class="hidden_player" data-video-id="0" style="display:none">
<iframe id="the_player0" width="640" height="360" frameborder="0" src="http://www.youtube.com/embed/2ktsHhz_n2A" type="text/html"></iframe>
</div>
<p>Show video 0 and start playing automatically</p>
<p>Stop video 0 from playing</p>
<br/><br/>
<div class="hidden_player" data-video-id="1" style="display:none">
<iframe id="the_player1" width="640" height="360" frameborder="0" src="http://www.youtube.com/embed/2ktsHhz_n2A" type="text/html"></iframe>
</div>
<p>Show video 1 and start playing automatically</p>
<p>Stop video 1 from playing</p>
</body>
</html>
I have created a function which access framed YouTube videos through the ID of the parent of the iframe (as specified in the YT Frame API), and executes the functions defined at the JS API.
See this answer for the code and a detailled Q&A section.
My code would be implemented in this way:
callPlayer(playerID, "stopVideo");

Categories