So I am using the jsplayer HTML5 player on my wordpress site, as well as some custom script to load in the next post and replace the old content once the video is finished:
$(document).ready(function(){
$(".video-js").livequery('ended', function(){
var sStr = "<?php echo get_permalink(get_adjacent_post(true,'',true)); ?>";
var adj_numb = "<?php
$adj = get_adjacent_post(true,'',true);
$numb = $adj->ID;
echo $numb
?>";
var cur_numb = "<?php echo $post->ID; ?>";
$.post(sStr, function(data) {
var content = $( data ).find( '#post-' + adj_numb);
$( "#post-" + cur_numb ).html( content );
var vid = VideoJS.setup( "vid" );
vid.play();
});
});
});
This works great, for 2 videos. It loads in the next video and plays it, and one after that, but after the 3nd video plays it just stops. I figure this means I have to sort of "reset" all my variables and start again from the beginning of the script, and that it's not doing this because of $(document).ready(function(), as it's already all loaded at this point.
Is there a standard way to loop through this script again, and re-set all the variables after its run once?
Or am I approaching the whole issue incorrectly?
Thanks!
Rendered JS:
$(document).ready(function(){
$(".video-js").livequery('ended', function(){
var sStr = "http://www.theloniousfilms.com/zachmath/volkswagon/";
var adj_numb = "94";
var cur_numb = "96";
$.post(sStr, function(data) {
var content = $( data ).find( '#post-' + adj_numb);
$( "#post-" + cur_numb ).html( content );
var vid = VideoJS.setup( "vid" );
vid.play();
});
});
});
HTML:
<div class="post-96 post type-post status-publish format-standard hentry category-zachmath" id="post-96">
<h2 id="director">Director Name</h2>
<h2 id="post_title">Post-Name
<span id="post_name">
"Hot Tub"
</span>
<span id="home">HOME</span>
<div class="entry">
<div class="video-js-box">
<!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --><br />
<video id="vid" class="video-js" width="640" height="360" preload autoplay poster="http://www.site.com/wp-content/uploads/2011/03/poster.jpg"><br />
<source src="http://d29zgp48wvs9kv.cloudfront.net/orkin.m4v" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /><br />
<source src="http://d29zgp48wvs9kv.cloudfront.net/orkin.ogv" type='video/ogg; codecs="theora, vorbis"' /><br />
<!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --><br />
<object class="vjs-flash-fallback" width="640" height="360" type="application/x-shockwave-flash"<br />
data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"><param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /><param name="allowfullscreen" value="true" /><param name="flashvars" value='config={"playlist":["http://www.theloniousfilms.com/wp-content/uploads/2011/03/poster.jpg", {"url": "http://d29zgp48wvs9kv.cloudfront.net/orkin.m4v","autoPlay":true,"autoBuffering":true}]}' /><!-- Image Fallback. Typically the same as the poster image. --><br />
</object><br />
</video>
</div>
I ended up going with a different method, where I pulled all the posts URLs into a array, then iterated through each of them, going to the next item in an array once playback finished.
Related
I have page where an instant search results are displaying using PHP & AJAX and <a> tag onclick from response item, it generate preview of track. Everything is working fine but when I update my jQuery version from 1.7.2 to 1.11.3 or 2.1.4. It open link instead of generating preview.
My code
<!--<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>-->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function($)
{
$(".videos .expand-video a.soundcloud").live("click", function(){
var scURL = $(this).attr("href");
var scID = $(this).attr("id");
var embedAudio = "<iframe width=\"100%\" height=\"166\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?url="+scURL+"&color=ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false\"></iframe>";
$("#sc-"+scID).html(embedAudio);
return false;
});
var timer = null;
$("#keyword").keyup(function()
{
if(timer)
{
clearTimeout(timer);
}
timer = setTimeout(function()
{
var sc_keyword = $("#keyword").val();
var obj = $(this);
if(sc_keyword != '')
{
$(".ajax_indi").show();
var str = $("#fb_expand").serialize();
$.ajax({
type: "POST",
url: "fetch.php",
data: str,
cache: false,
success: function(htmlresp)
{
$('#results').html(htmlresp);
$(".ajax_indi").hide();
}
});
}
else
{
alert("Search for your favourite news");
$("#keyword").focus();
}
}, 1000);
});
});
</script>
I know .live() has been removed in version 1.9 onwards. So, I tried to update it to .on() but does not done it successfully
What I have tried to update from .live() to .on() is below
$(".videos .expand-video a.soundcloud").on("click", 'a', function(){
var scURL = $(this).attr("href");
var scID = $(this).attr("id");
var embedAudio = "<iframe width=\"100%\" height=\"166\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?url="+scURL+"&color=ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false\"></iframe>";
$("#sc-"+scID).html(embedAudio);
return false;
});
HTML OUTPUT Response of ajax request
<div class="videos" id="sc-80912043">
<div class="expand-video"> <a class="soundcloud" id="80912043" href="https://api.soundcloud.com/tracks
/80912043"><span></span> <img src="https://i1.sndcdn.com/avatars-000033051760-4ugg0i-large.jpg" width
="120" height="90" title="Play" alt="Play"/> </a> </div>
<div class="details">
<h6>DJ MHA - Menu Chad De (MHA Remix)</h6>
<p class="link">Gangzta Khan</p>
<p class="desc">DJ MHA - Menu Chad De (MHA Remix)..
Gangzta Khan ..</p>
</div>
</div>
<div class="videos" id="sc-24508938">
<div class="expand-video"> <a class="soundcloud" id="24508938" href="https://api.soundcloud.com/tracks
/24508938"><span></span> <img src="https://i1.sndcdn.com/avatars-000002625883-ve8pmk-large.jpg" width
="120" height="90" title="Play" alt="Play"/> </a> </div>
<div class="details">
<h6>Halka Halka Suroor - MHA Mix</h6>
<p class="link">DJ MHA</p>
<p class="desc">Yeh Jo Halka Halka Suroor Hai
Direct Download Link:
http://www.djmha.com/get.php?file=Halka_Halka_Suroor_-_MHA_Mix.mp3</p>
</div>
</div>
<div class="videos" id="sc-65996317">
<div class="expand-video"> <a class="soundcloud" id="65996317" href="https://api.soundcloud.com/tracks
/65996317"><span></span> <img src="https://i1.sndcdn.com/avatars-000002625883-ve8pmk-large.jpg" width
="120" height="90" title="Play" alt="Play"/> </a> </div>
<div class="details">
<h6>Zarina Taylor - (DJ MHA Remix)</h6>
<p class="link">DJ MHA</p>
</div>
</div>
You're being too specific with your selector before calling .on(). The way the function works is you select elements that will always exist on the page, and bind the delegated event handler to those. Since you're replacing the content of the <div> elements with class videos, your code should be this:
$(".videos").on("click", ".expand-video a.soundcloud", function(){
var scURL = $(this).attr("href");
var scID = $(this).attr("id");
var embedAudio = "<iframe width=\"100%\" height=\"166\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?url="+scURL+"&color=ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false\"></iframe>";
$("#sc-"+scID).html(embedAudio);
return false;
});
First, we select the .videos elements, then we bind a delegated event handler for a.soundcloud elements which are inside a .expand-video element (which are in turn inside a .videos element). That way, when you update the content of one of those elements in this line - $("#sc-"+scID).html(embedAudio); - the delegated event handler still exists.
I dont know why this worked in an old version!!!
So just for one video
<div class="videos" id="sc-80912043">
<div class="expand-video"> <a class="soundcloud" id="80912043" href="https://api.soundcloud.com/tracks
/80912043"><span></span> <img src="https://i1.sndcdn.com/avatars-000033051760-4ugg0i-large.jpg" width
="120" height="90" title="Play" alt="Play"/> </a> </div>
<div class="details">
<h6>DJ MHA - Menu Chad De (MHA Remix)</h6>
<p class="link">Gangzta Khan</p>
<p class="desc">DJ MHA - Menu Chad De (MHA Remix)..
Gangzta Khan ..</p>
</div>
</div>
This is a problem i have had a few times .on does not act the same as live with the active binding even though it's supposed to...
function gotAJAXResults(){
$(".videos .expand-video a.soundcloud").unbind("click");
$(".videos .expand-video a.soundcloud").click(function(e){
e.preventDefault();
var scURL = $(this).attr("href");
var scID = $(this).attr("id");
var embedAudio = "<iframe width=\"100%\" height=\"166\" scrolling=\"no\" frameborder=\"no\" src=\"https://w.soundcloud.com/player/?url="+scURL+"&color=ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false\"></iframe>";
$("#sc-"+scID).html(embedAudio);
return false;
});
}
Ok so now your AJAX call becomes
$.ajax({
type: "POST",
url: "fetch.php",
data: str,
cache: false,
success: function(htmlresp)
{
$('#results').html(htmlresp);
gotAJAXResults();
$(".ajax_indi").hide();
}
});
This method will then force it to bind the event when ajax receives and has inserted them into the page. (DOM scope)
I have integrated flowplayer in my website.
As a next step, I want to trigger its video play function, so that when a user plays a video, she/he will simply press a play button, that will call a function.
Can anybody please help me achiving that?
I am trying to do this:
<script language="javascript">
$(document).ready(function(){
$( ".fp-play" ).change(function() {
alert( "Handler for .click() called." );
});
});
</script>
This is my HTML code:
<div class="artist_vidoe_player fl clear">
<div class="flowplayer" data-swf="<?php echo WEB_URL; ?>assets/styles/frontend/js/flowplayer.swf" data-ratio="0.4167">
<video>
<source type="video/flv" src="<?php echo WEB_URL; ?>assets/styles/uploads/videos/<?php echo $rowvid->v_uploadname; ?>">
</video>
</div>
<div style="float:left; margin-top:15px;">
<div class="clear"></div>
<h1><?php echo $rowvid->v_filename; ?></h1>
<p>258 Views</p>
<p><img src="<?php echo WEB_URL; ?>assets/styles/frontend/images/stars_img.png" width="90" height="16" alt="" /></p>
</div>
</div>
The above code dynamically generates my videos, but this is all not working for me anyway.
You can use .click() instead of .change() as well as using .trigger() to trigger click event:
$(document).ready(function(){
$( ".fp-play" ).click(function() {
alert( "Handler for .click() called." );
}).trigger('click');
});
I need to get the url for the artists track from the mysql databse for it to be played through jplayer. I achieved it with the normal html audio controls but cannot do it with jplayer as the audio source is entered in javascript.
Here's how i achieved it with the html player;
<?php
include ("../database.php");
$result = mysql_query("SELECT * FROM tracks WHERE artistname='$artistname'");
while($row = mysql_fetch_array($result)){
?>
<br><br>
<audio controls="controls" height="50px" width="100px">
<source src=<?php echo $row['trackurl'] ?> type="audio/mp3" />
<embed height="50px" width="100px" src="song.mp3" />
</audio>
<?php } <?
Heres the javascript for jplayer:
<script type="text/javascript">
$(document).ready(function(){
$("#jquery_jplayer_1").jPlayer({
ready: function () {
$(this).jPlayer("setMedia", {
mp3: "http://localhost/uploads/dde85d7907e516545ba0860ef1ac23f2.mp3"
});
},
swfPath: "../jplayer",
supplied: "mp3"
});
});
The url from the mysql databse needs to go where it says:
mp3: "http://localhost/uploads/dde85d7907e516545ba0860ef1ac23f2.mp3"
You can use AJAX to get the the value and pass it to the jPlayer
In your javascript make a variable of track like
var mp3file='<?php echo $row['trackurl']; ?>';
and then
$(this).jPlayer("setMedia", {
mp3: "mp2file"
});
This will work if you fetching a single song. If you fetching data in array then you need AJAX
Can anyone explain how to embed a swf object into a facebook canvas page via PHP.
<?php
function sswf($swf,$swfh,$swfw) {
echo "<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'
codebase='http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0' ID=objects WIDTH=$swfw HEIGHT=$swfh><PARAM
NAME=movie VALUE='$swf'><EMBED src='$swf' WIDTH=$swfw HEIGHT=$swfh TYPE='application/x-shockwave-flash'
PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'></OBJECT>";
}
$mf = "mmmm1.swf";
sswf($mf,690,1000);
?>
The code above no longer works although it did last week.... What's wrong with it?
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var params = {allowFullScreen:'false', allowscriptaccess:'always', wmode:'opaque'};
var flashvars = {};
var attributes = { name:"xxx", id:"xxx" };
swfobject.embedSWF("xxx.swf?<? echo(time()) ?>", "xxx", "520", "500", "9.0", null, flashvars, params, attributes);
</script>
<div id="fb-root"></div>
<div id="xxx">
<h1>You need at least Flash Player 9 to view this page.</h1>
<p><img src="https://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></p>
</div>
So I am using the jsplayer HTML5 player on my wordpress site, as well as some custom script to load in the next post and replace the old content once the video is finished:
$(document).ready(function(){
$(".video-js").bind('ended', function(){
var sStr = "<?php echo get_permalink(get_adjacent_post(true,'',true)); ?>";
var adj_numb = "<?php
$adj = get_adjacent_post(true,'',true);
$numb = $adj->ID;
echo $numb
?>";
var cur_numb = "<?php echo $post->ID; ?>";
$.post(sStr, function(data) {
var content = $( data ).find( '#post-' + adj_numb);
$( "#post-" + cur_numb ).html( content );
var vid = VideoJS.setup( "vid" );
vid.play();
});
});
});
This works great, for exactly one video. It loads in the next video and plays it, but after the 2nd video plays it just stops. I figure this means I have to sort of "reset" all my variables and start again from the beginning of the script, and that it's not doing this because of $(document).ready(function(), as it's already all loaded at this point.
Is there a standard way to loop through this script again, and re-set all the variables after its run once?
Thanks!
EDIT: Rendered JS:
$(document).ready(function(){
$(".video-js").live('ended', function(){
var sStr = "http://www.theloniousfilms.com/zachmath/volkswagon/";
var adj_numb = "94";
var cur_numb = "96";
$.post(sStr, function(data) {
var content = $( data ).find( '#post-' + adj_numb);
$( "#post-" + cur_numb ).html( content );
var vid = VideoJS.setup( "vid" );
vid.play();
});
});
});
HTML:
<div class="post-96 post type-post status-publish format-standard hentry category-zachmath" id="post-96">
<h2 id="director">Zach Math</h2>
<h2 id="post_title">Orkin -
<span id="post_name">
"Hot Tub"
</span>
<span id="home">HOME</span>
<div class="entry">
<div class="video-js-box">
<!-- Using the Video for Everybody Embed Code http://camendesign.com/code/video_for_everybody --><br />
<video id="vid" class="video-js" width="640" height="360" preload autoplay poster="http://www.theloniousfilms.com/wp-content/uploads/2011/03/poster.jpg"><br />
<source src="http://d29zgp48wvs9kv.cloudfront.net/orkin.m4v" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"' /><br />
<source src="http://d29zgp48wvs9kv.cloudfront.net/orkin.ogv" type='video/ogg; codecs="theora, vorbis"' /><br />
<!-- Flash Fallback. Use any flash video player here. Make sure to keep the vjs-flash-fallback class. --><br />
<object class="vjs-flash-fallback" width="640" height="360" type="application/x-shockwave-flash"<br />
data="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf"><param name="movie" value="http://releases.flowplayer.org/swf/flowplayer-3.2.1.swf" /><param name="allowfullscreen" value="true" /><param name="flashvars" value='config={"playlist":["http://www.theloniousfilms.com/wp-content/uploads/2011/03/poster.jpg", {"url": "http://d29zgp48wvs9kv.cloudfront.net/orkin.m4v","autoPlay":true,"autoBuffering":true}]}' /><!-- Image Fallback. Typically the same as the poster image. --><br />
</object><br />
</video>
</div>
Looks like the HTML is being rewritten by
$( "#post-" + cur_numb ).html( content );
Change
$(".video-js").bind('ended', function(){
to
$(".video-js").live('ended', function(){
that should take care of it.
Also, change
$( "#post-" + cur_numb ).html( content );
with
$( "#post-" + cur_numb ).replaceWith( content );
i ended up just pulling all the post urls into an array, then iterated through each of them, moving to the next item in an array once the previous video finished playback.