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
Related
How would I return the value that's output by my PHP file? I've tried a few different ways like PHP each in the source but I could never get a working return.
PHP
<?php
$f_contents = file("/var/www/html/scripts/songs.index");
$line = $f_contents[array_rand($f_contents)];
$data = $line;
/** print the contents of the names array */
echo($data);
?>
Example of the PHP files return:
/var/www/html/uploads/Music/My_Life_NF_Perception_2017.mp3
HTML
<html>
<head>
<?php include "radio.php" ?>
</head>
<audio controls>
<source src="<?php echo $data; ?>" type="audio/mp3">
</audio><br />
</html>
Okay so I figured it out.
I had to change the HTML to:
<audio controls>
<source id="source" src="" type="audio/mp3">
Your browser does not support the audio element.
</audio>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$.ajax({
url: 'test.php',
data: { attr1: 'value1' },
success: function( data ) {
console.log(data);
$('audio #source').attr('src', data);
$('audio').get(0).load();
$('audio').get(0).play();
}
});
</script>
Lastly, I also had an issue in my index file. Instead of pointing from the root it needed to point from current folder so I removed the first few directories and it now looks like:
/uploads/Music/My_Life_NF_Perception_2017.mp3
try this
explode("/",$data);
and get after uploads/Music/My_Life_NF_Perception_2017.mp3
I want to load a few flash banners on my single page.
I'm using swfobject ( http://code.google.com/p/swfobject/ ). When i'm loading these ten banners in traditional way - just static way, often some of them (3-4) are not loaded, just empty field, when I refresh page - there are always some banners not loaded. Is there a way to load them all in a way, that they will work properly? : ) Maybe some asynchronous loading?
I'm using codeigniter and PHP.
I'm trying to load them in that way:
<?php foreach($category_res as $results){ ?>
<script type="text/javascript">
var id = <?php echo $results['id'];?>;
swfobject.registerObject("banner"+id, "9.0.115");
</script>
<div class="baner">
<div class="kreacja" style="padding-top:25px;" onclick="return false;">
<object id="banner<?php echo $results['id']; ?>" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" >
<object class="flash_banner" type="application/x-shockwave-flash" data="<?php echo '/prod_bann/kategorie/'.$results['category_name'].'/'.$results['file']; ?>"></object>
</object>
</div>
</div>
<?php } ?>
UPDATE
I've also tried dynamic SWf fiels embedding - but it's even worse. More banners are not loaded, here's code:
<script type="text/javascript">
var id = <?php echo $results['id'];?>;
var path = "<?php echo '/prod_bann/kategorie/'.$results['category_name'].'/'.$results['file']; ?>";
swfobject.embedSWF(path, "banner"+id, "300", "120", "9.0.0");
</script>
<div class="baner">
<div class="kreacja" style="padding-top:25px;" onclick="return false;">
<div id="banner<?php echo $results['id']; ?>" >
</div>
</div>
</div>
<?php } ?>
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>
I am using Facebox. I have to play mp3files in Facebox. I included facebox.js and facebox.css
My view code is:
<script type="text/javascript">
$(document).ready(function () {
$('a[rel*=facebox]').facebox();
}
</script>
$res= explode('/',$val['audio_file']);
<?=$res['1'];?>
I have to play this mp3 file in Facebox. Is it possible?
I have linked the mp3 file in anchor tag, then can I play that file in a facebox. Now it plays in big screen.
Include it in view
<script type="javascript">
$('#play').live('click', function(e) {
e.preventDefault();
link=this.href;
jQuery.facebox({ ajax: link });
});
</script>
<a id="play" href="<?=site_url('admin/test/playmp3/'.$val['id']);?>"><?=$res['1'];?></a>
Include it in controller
function playmp3($id)
{
$this->data['mp3'] = $this->test_model->getmp3($id);
$this->load->vars($this->data);
echo $this->load->view( $this->config->item('APP_template_dir').'admin/playmp3_view');
}
Create a new page playmp3_view and include it
<div style="">
<object type="application/x-shockwave-flash" data="<?=base_url().$this->config->item('APP_assets_admin').'/'.$this->config->item('APP_js');?>/player_mp3.swf" width="200" height="20">
<param name="movie" value="<?=base_url().$this->config->item('APP_assets_admin').'/'.$this->config->item('APP_js');?>/player_mp3.swf" />
<param name="FlashVars" value="mp3=<?=base_url().'uploads/'.$mp3->audio_file?>" /></object>
</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").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.