Play audio file on website - php

I'm just wondering how, and which audio player I should use to allow my visitors to play audio files on my PHP-based website.
Thanks!

try this
<?php
$path = "PATH OF YOUR AUDIO FILE";
$image = "PATH OF YOUR IMAGEFILE";;?>
<div class="demomain">
<br>
<div style="margin: 0 0 0 30px;" id="mediaspace" name="mediaspace"><embed height="395" width="500" flashvars="javascriptid=JW&autostart=false&width=500&height=395&image=<?php echo $image; ?>&file=<?php echo $path; ?>" allowfullscreen="true" wmode="transparent" allowscriptaccess="always" quality="high" name="JW" id="JW" style="undefined" src="http://player.longtailvideo.com/player4.6.swf" type="application/x-shockwave-flash"> </div>
<?php
echo '<script type="text/javascript">
var s1 = new SWFObject("","JW","500","395","9");
s1.addParam("allowscriptaccess", "always");
s1.addParam("wmode","transparent");
s1.addParam("allowfullscreen","true");
s1.addVariable("javascriptid", "JW");
s1.addVariable("autostart","false");
s1.addVariable("image","' . $image . '"));
s1.addVariable("width","500");
s1.addVariable("height","395");';
echo 's1.addVariable("file","' . $path . '");';
echo 's1.write("mediaspace");';
echo '</script>';
?>
</div>

HTML 5 has an audio player tag,see this:
http://www.w3schools.com/html5/att_audio_src.asp
it is supported on major browsers, but it depends on the format of the audio file
you can see this: http://jplayer.org/ a jquery one,

The open source jPlayer works well and is very customisable - uses HTML/CSS for the interface. Will use HTML5 if it can, and fallback to Flash if not. Requires jQuery.
Website: http://jplayer.org/

You can try Flash Player. I think it will suite your requirement. Of course you should have the flash player installed, but practically almost all internet users have the flash player installed in their machines.

try this
<object height="81" width="100%">
<param name="movie" value="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F32222617&show_comments=true&auto_play=true">
</param>
<param name="allowscriptaccess" value="always"></param>
<embed allowscriptaccess="always" height="81" src="http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F32222617&show_comments=true&auto_play=true&repeat=1" type="application/x-shockwave-flash" width="100%" loop="yes" autoresume="1" repeat="1">
</embed>
</object>

use this <audio controls><source src="<?php echo $pathtofile ?>" type="audio/mpeg">Error loading</audio> It works for me.

Related

How to encode video URLs in wordpress using base64?

<?php
$vid = get_post_meta($post->ID,'videourl', true);
$video = base64_encode($vid);
$embedvideo = get_post_meta($post->ID,'embedvideo', true);
$sefurL = get_bloginfo('template_url', true);
if($video != "") { ?>
<?php if ( !wp_is_mobile() ) {
echo'<object id="player" width="800" height="500" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">
<param name="flashvars" value="file='.$video.' />
<param name="allowfullscreen" value="true" />
<param name="allowscriptaccess" value="always" />
<param name="src" value="'.$sefurL.'/inc/tools/jwplayer/player.swf" />
<embed src="'.$sefurL.'/inc/tools/jwplayer/player.swf" autostart=false" wmode="opaque" allowscriptaccess="always" quality="high" FlashVars="file='.$video.'&width=800&height=500&skin='.$sefurL.'/inc/tools/jwplayer/blueratio.zip&repeat=false&autostart=false&image=big=true" quality="high" bgcolor="#000" width=800 height=500 name="jwplayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="https://www.macromedia.com/go/getflashplayer" allowfullscreen=true />
</embed>
</object>';
} else {
echo '<video src="'.$video.'" controls>
Your browser does not support the <code>video</code> element.
</video>';
}
?>
<?php } elseif($video == "" && $embedvideo != "") { ?>
<?php echo $embedvideo; ?>
<?php } else {
wpautop(the_content());
} ?>
As you see in the code I used $video = base64_encode($vid); but when I do it in this way video not working more, so I don't have any experience with the base64 encoding I just searched on the Google but I couldn't find the right way to do it.
Can anyone help me?
Maybe you should be using base_64_decode(), it's likely the 'videourl' is already base64 encoded. See how base64_encode() works in the
PHP Docs.
Try to echo the value of $vid to establish if it is already base64 encoded or not.

Change iframe source from another iframe when both the iframe are in same page

I have this following code where i cannot play the player in second iframe from first iframe . Although this works fine if the link to play song is in the main page and not inside the first iframe
<script type="text/javascript">
function music(dir) {
alert(dir);
var iframe = document.getElementById("player");
iframe.src = dir;
}
</script>
<iframe src="home.php" frameborder="0" scrolling="no" width="100%" height="100%" style="background:#993333"></iframe>
<iframe id="player" src="player.php" frameborder="0" scrolling="no" width="400px" height="100px" style="background:#66FF99"></iframe>
//home.php
<a href="#" onclick="return music('player.php?item=test2')" >Song2</a>
//player.php
<object type="application/x-shockwave-flash" data="dewplayer.swf?mp3=mp3/music.mp3&autostart=1" width="200" height="20" id="dewplayer"><param name="wmode" value="transparent" />
</object>
Example:
main.php
<script type="text/javascript">
function music(dir) {
alert(dir);
var iframe = document.getElementById("player");
iframe.src = dir;
}
</script>
<iframe src="home.php" frameborder="0" scrolling="no" width="100%" height="100%" style="background:#993333"></iframe>
<iframe id="player" src="player.php" frameborder="0" scrolling="no" width="400px" height="100px" style="background:#66FF99"></iframe>
player.php
<?php if(!empty($_GET['item'])){echo '<div>item = '.$_GET['item'].'</div>';} ?>
<object type="application/x-shockwave-flash" data="dewplayer.swf?mp3=mp3/music.mp3&autostart=1" width="200" height="20" id="dewplayer"><param name="wmode" value="transparent" />
</object>
home.php
<a href="#" onclick="parent.music('player.php?item=test2')" >Song2</a>
First iframe doesn't have an ID.
Both those iframes are not part of each other's document. So if you have to change url of one from the other you have to bring in parent in the picture.
You could use the new window.postMessage API to send a message from one remote frame to it's parent, and then have the parent window proxy that make message back to the other iframe by passing that message onto the other iframe.
For documentation on this, see the Mozilla page (https://developer.mozilla.org/en-US/docs/DOM/window.postMessage)

Flash Banner and PHP

For some reason I'm trying to do:
<OBJECT id="affMV737" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="468" height="60">
<param name="movie" value="http://www.domain.com/view.php?banner_id=1">
<param name="allowScriptAccess" value="always">
<embed src="http://www.domain.com/view.php?banner_id=1" width="468" height="60" allowScriptAccess="always" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></embed>
</object>
I'm printing the FULL URL in the php but the flash is not loading...
but If i change the src in the flash code to the printed result in the php, the banner is working.
any advice?
thanks.
Not clear what you want but I guess this will help
instead of this:
http://www.domain.com/view.php?banner_id=1
try like this:
<?php echo file_get_contents('http://www.domain.com/view.php?banner_id=1');?>
update:
Another guess.. You need change your view.php to something like this:
header('Content-type: application/x-shockwave-flash');
echo file_get_contents('http://domain.com/files/bnrs/blabla.swf');

Get the Html Tag as string

I have a script that gets embed code for me.I am using php simple html dom parser.The code i am using is like this :
foreach ($html->find('object embed') as $embedCode)
{
echo $embedCode;
}
and the out put is :
<embed width="100%" height="320" flashvars="config=http://server0.stream2k.com/playerjw/vConfigCdn.php?vkey=c2053010dadfdd331145"
allowfullscreen="true" allowscriptaccess="always"
src="http://server0.stream2k.com/playerjw/player-licensed56.swf"
pluginspage="http://www.macromedia.com/go/getflashplayer"
type="application/x-shockwave-flash" wmode="transparent">
but it's showing in my browser as a flash screen.I want to print it as a single string.
Can anyone tell me how can i get it as a single string not the video screen.
Thanks in advance
The return of GetMovie() :
<embed wmode="transparent" type="application/x-shockwave- flash"
pluginspage="http://www.macromedia.com/go/getflashplayer"
src="http://server0.stream2k.com/playerjw/player- licensed56.swf"
width="100%" height="320" allowscriptaccess="always" allowfullscreen="true" flashvars="config=http://server0.stream2k.com/playerjw/vConfigCdn.php?vkey=f3513b19d1149102e116" />
use htmlspecialchars:
foreach ($html->find('object embed') as $embedCode)
{
echo htmlspecialchars($embedCode);
}
Try to put output string in htmlspecialchars: echo htmlspecialchars($embedCode);
You can try something like this :
<pre>
<embed width="100%" height="320" flashvars="config=http://server0.stream2k.com/playerjw/vConfigCdn.php?vkey=c2053010dadfdd331145"
allowfullscreen="true" allowscriptaccess="always"
src="http://server0.stream2k.com/playerjw/player-licensed56.swf"
pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent">
​</pre>
​​​​​​​​​​​​​​​​​​​​​
Try add this before your "for" loop:
echo '<xmp>';
this will echo all charactors but not display as html code.

Embed randomly named MP3

Here's my code:
<embed src="/sound/lowyourchicken.mp3"
width="140" height="40" autostart="true" loop="TRUE">
</embed>
I would like the src for the .mp3 to take in to account that there are many randomly named .mp3 files in the /sound/ directory, and to choose one at random each time the page is opened. Any clues for me?
My server is PHP enabled but I'd like to keep this as simple as possible.
This should do it:
$files = glob("/path/to/directory/*.mp3");
$random = array_rand($files)
Then do this:
<embed src="<?php echo $random ?>"
width="140" height="40" autostart="true" loop="TRUE">
</embed>
array_rand returns what random index it chose, so you'll need to do this:
<embed src="<?php $files[ $random ] ?>"
Try This:
It will Work, I used original code found in answers and did some tweaking by adding array($files) in the $random = array_rand(); variable statement
You will first need to put the PHP code in the body like this
<?php
$files = glob("assets/songs/SayYesToLove/*.mp3");
$random = array_rand(array($files));
?>
next add this just outside that php code in the body
<embed src="<?php echo $files[$random]; ?>" width="140" height="40" autostart="true" loop="TRUE">
</embed>
Please Notice the echo output in the src file. This will ensure it gets outputted to your page. Also don't forget to use the ; at the end of every php variable statement as this can through some errors.

Categories