 |
|
|
| View previous topic :: View next topic |
| Author |
Message |
Solaris
Joined: 25 Dec 2004 Posts: 5 Location: The Fortress
|
Posted: Sat Dec 25, 2004 4:36 pm "Radio" using iframe....I think? |
|
|
|
Hey everybody,
I'm a very green newbie who is just learning html, so I'm humbly asking for assistance with a little project that I saw on another website that is no longer in existance.
Here's the deal:
I have a website and I want to add a "radio" that will contain original music from my site's members. I saw the "radio" on another website a few months back and I was able to get the html code for it. I've tried getting assistance from the webmaster of the site, but the site is no longer in existance and my email went unanswered.
The main thing I need help with is learning how and where to place the links so that there's a list of tunes "inside" of the radio in an iframe (I think).
Here's the code to the "radio" which I will call "boombox":
| Code: |
<head>
<title>FortWayneHipHop.com BoomBox</title>
<style type="text/css">
<!--
body {border: 0; margin: 0; background: buttonface;}
.fbutton{BACKGROUND-COLOR: buttonface; BORDER-BOTTOM: buttonface 1px solid;
BORDER-LEFT: buttonface 1px solid; BORDER-RIGHT: buttonface 1px solid;
BORDER-TOP: buttonface 1px solid;}
.dbutton{BACKGROUND-COLOR: buttonface; BORDER-BOTTOM: buttonshadow 1px solid;
BORDER-LEFT: buttonhighlight 1px solid; BORDER-RIGHT: buttonshadow 1px solid;
BORDER-TOP: buttonhighlight 1px solid;}
.pbutton{BACKGROUND-COLOR: buttonface; BORDER-BOTTOM: buttonhighlight 1px solid;
BORDER-LEFT: buttonshadow 1px solid; BORDER-RIGHT: buttonhighlight 1px solid; BORDER-TOP: buttonshadow 1px solid;}
.ebutton{BACKGROUND-COLOR: buttonface;
BORDER-BOTTOM: #000000 1px solid; BORDER-LEFT: buttonface 1px solid; BORDER-RIGHT: #000000 1px solid;
BORDER-TOP: buttonface 1px solid;}
.rbutton{BACKGROUND-COLOR: buttonshadow; BORDER-BOTTOM: buttonface 1px solid; BORDER-LEFT: #000000 1px solid;
BORDER-RIGHT: buttonface 1px solid; BORDER-TOP: #000000 1px solid;}
-->
</style>
</head>
<body>
<table border="0" width="100%" cellspacing="0" cellpadding="10">
<tr><td width="100%">
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr><td width="100%" class="pbugtton">
<table border="0" width="100%" cellspacing="0" height=100 cellpadding="0">
<tr><td width="100%" height=240 class="rbutgton">
<iframe SCROLLING=yes name=files width=100% height=100% src="files.php?sort=1&displaynumber=50" border=0 frameborders=0></iframe>
</td></tr>
</table>
</td></tr>
</table>
</td></tr><tr><td valign=top height=120>
<center>
<form><INPUT TYPE="button" VALUE="Sort By Artist" onClick="parent.files.location='files.php?sort=2&displaynumber=50'">
<INPUT TYPE="button" VALUE="Sort By Title" onClick="parent.files.location='files.php?sort=1&displaynumber=50'"></form>
<img src=explicitlyrics.jpg width="82" height="54">
<OBJECT ID=video1
CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"
HEIGHT=60 WIDTH=275>
<PARAM NAME="controls" VALUE="ControlPanel,StatusBar">
<PARAM NAME="console" VALUE="fhh_boombox">
<PARAM NAME="autostart" VALUE="false">
<PARAM NAME="src" VALUE="">
<EMBED SRC="" type="audio/x-pn-realaudio-plugin" CONSOLE="fhh_boombox" CONTROLS="ControlPanel,StatusBar"
HEIGHT=60 WIDTH=275 AUTOSTART=false>
</OBJECT>
<img src=explicitlyrics.jpg width="82" height="54">
<br> <font size=1 face=verdana color=#000000>Copyright 2004-2005 FortWayneHipHop.com</td></tr>
</table>
<iframe name="hidden" width="0" height="0" src="blank.html" border="0" frameborders="0"></iframe>
</body> |
If someone would be so kind as to help a girl out and give me some
direction, I would greatly appreciate it and would most definitely credit you on my site. |
|
kanenas

Joined: 14 Dec 2004 Posts: 191
|
Posted: Sun Jan 09, 2005 2:25 pm Object communication across iframe |
|
|
|
Here's a solution with accompanying code: document in IFRAME uses window.parent to access player and the SetSource function of RealPlayer javascript API to change the file being played, and document containing IFRAME uses standard document.getElementById function to access objects in IFRAME document.
I replaced tables with style as use of tables was HTML abuse.
I also recommend adding code to let visitor pick player in boombox (RealPlayer, QT or MediaPlayer). If you attempt this, you will need to define player.SetSource for plugins other than RealPlayer (among other tasks); see commented code in function setFilesPlayer().
EDITED: Added code to address different browsers' odd style sheet handling.
Make sure you change '$startfile' in boombox.php to whatever initial file you want (or '').
boombox.php (outer page; Jan 20, 2005):
| Code: |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"
>
<?php
$browser = get_browser(null);
$songdir = '/songs/';
//Initial file to load in player
$startfile = $songdir . 'Artist/Song.mp3';
$player = array(
/*
'controls' => 'ControlPanel,StatusBar',
'height' => '64',
*/
'controls' => 'All',
'height' => '96',
'width' => '320',
);
if (preg_match('/Gecko/', $_SERVER['HTTP_USER_AGENT'])) {
/*
Mozilla/Firebird (and presumably NS6/7) don't seem to like
'%' unit for iframe height. Why, Gecko, why?
*/
$plst['height'] = '260px';
} else {
$plst['height'] = '60%';
}
?>
<head>
<title>FortWayneHipHop.com BoomBox</title>
<link REL='stylesheet' TYPE='text/css' HREF='/css/main.css' />
<style type="text/css">
<!--
body {
border: 0;
margin: 0;
background: ButtonFace;
<?php
if ('IE' == $browser->browser && 6 == $browser->majorver) {
/*
if body height isn't set for IE6, iframe {height: 60%} causes iframe to
be more than 100% of page height. Why, IE6? Also, setting body height
to 100% sometimes causes vertical scrollbar, though border & margin of
0 may prevent this.
*/
?>
height: 100%;
<?php
}
?>
}
iframe.files {
margin: 1%;
height: <?= $plst['height'] ?>;
/*height: 60%;*/
width: 96%;
background-color: ButtonFace;
border-top: ButtonShadow 3px solid;
border-bottom: ButtonHighlight 3px solid;
border-left: ButtonShadow 3px solid;
border-right: ButtonHighlight 3px solid;
}
.copy_notice {
font-size: smaller;
font-family: verdana, sans-serif;
color: black;
}
-->
</style>
</head>
<body onload="setGlobals();">
<center>
<iframe id='files' name='files' src="files.php" SCROLLING=yes>
<!-- For browsers that don't support iframes. Not yet implemented.-->
<a href="files.php?link=direct"></a>
</iframe>
</center>
<center>
<form action='' id='sortBy'>
<INPUT TYPE="button" VALUE="Sort By Artist" onClick="parent.files.location='files.php?sort=artist'" />
<INPUT TYPE="button" VALUE="Sort By Title" onClick="parent.files.location='files.php?sort=title'" />
</form>
<img src=explicitlyrics.jpg width="82" height="54">
<OBJECT ID='player'
CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA"
HEIGHT=<?= $player['height']?> WIDTH=<?= $player['width'] ?>>
<PARAM NAME="src" VALUE="<?= $startfile ?>">
<PARAM NAME="autostart" VALUE="false">
<PARAM NAME="controls" VALUE="<?= $player['controls'] ?>">
<EMBED ID='player_emb' type="audio/x-pn-realaudio-plugin"
SRC="<?= $startfile ?>"
AUTOSTART='false' HEIGHT=<?= $player['height'] ?> WIDTH=<?= $player['width'] ?>
CONTROLS='<?= $player['controls'] ?>'
</EMBED>
</OBJECT>
<img src=explicitlyrics.jpg width="82" height="54"><br>
<script type='text/javascript'><!--
document.getPlayer = function () {
player = this.getElementById('player_emb');
if (! player) {
player = this.getElementById('player');
}
return player;
}
function setGlobals() {
if (null != files && files.setGlobals) {
//files.setGlobals is called both here and files.php, as either may
//be the last to load
files.setGlobals();
}
}
function play(url) {
if (null != player) {
player.DoStop();
player.SetSource(url);
player.DoPlay();
} else {
//alert("There's no media player.");
}
}
document.play=play;
var player = document.getPlayer();
var files = document.getElementById('files');
if (files.document) {
files=files.document;
} else if (files.contentDocument) {
files = files.contentDocument;
}
document.files = files;
document.player = player;
//-->
</script>
<span class='copy_notice'>Copyright 2004-2005 FortWayneHipHop.com</span>
<iframe name="hidden" width="0" height="0" src="blank.html" border="0" frameborders="0"></iframe>
</body>
</html>
|
EDITED: Originally, method of filling $songs in files.php was left to the user. This (and additional features) have been added to the code below. See the comment at the beginning of the file for usage information.
files.php (inner page; Jan 20, 2005):
| Code: |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"
>
<?php
/*
There are a few configuration options users of this script should know about:
* The (virtual, i.e. webspace) directory holding songs is held in $opts['songdir']. I've set it to '/songs/'. Either create a directory named "songs" in DOCROOT or change $opts['songdir'].
* In songdir, create a sub-directory for each artist. Store audio files in these subdirectories.
* You probably don't need to set $DOCROOT default unless you want to
run this script from the command line.
* $opts['scheme'] holds the URL scheme for audio files. Set it to 'http',
'xmms', 'rtsp' or whatever connection scheme you want to use for audio
files. Currently, all audio files must share a scheme, but it wouldn't be
too hard to make the scheme file-extension dependant.
* If you want to store songs for an artist but don't want some (or all) of
the artist's songs to be listed, create a file named '.ignore' in the artist's directory. An empty '.ignore' file will cause this script to skip the artist entirely. If '.ignore' is not empty, the contents of the first line will be
interpreted as a Perl-compatible regular expression (PCRE). Any
filenames which match the RE will be skipped. For full PCRE syntax, see:
http://www.php.net/manual/en/reference.pcre.pattern.syntax.php
Example contents for '.ignore':
-- ignore files starting with A through G ('^' matches the beginning of a
string):
^[A-G]
-- ignore files starting with a lowercase letter
^[a-z]
-- ignore files containing a number:
[0-9]
-- ignore ogg and mp3 media files ('$' matches the end of a string):
\.(ogg|mp3)$
* $opts['audioext_RE'] is a PCRE fragment listing extensions of files to be
recognized as audio files. Add any file extensions you want, but make
sure all extensions are separated with '|' characters
*/
$DOCROOT = '/var/www/htdocs/';
if (isset($_SERVER['DOCUMENT_ROOT'])) {
$DOCROOT = $_SERVER['DOCUMENT_ROOT'];
}
//make sure DOCROOT ends w/ '/'
$DOCROOT = preg_replace('/\/?$/', '/', $DOCROOT);
//$opts['songdir'] holds virtual root of songs
$opts = array (
//URL scheme for audio files. e.g. 'http', 'rtsp', 'pnm', 'mms'
'scheme' => 'http',
//virtual directory that will hold all artist directories
'songdir' => '/songs/',
//should spaces be inserted before upper case letters in artists' names?
'spacify' => 0,
//'spacify' => array('artist'),
//name to use in links to this script
'selfname' => '',
//primary sort field
'sort' => 'artist',
//sort direction; 1 is ascending, -1 is descending
'sortdir' => 1,
//matches audio file extensions
'audioext_RE' => '(?:mpa|mpg|mp3|mp4|wma|asx|ra|rpm|rm|ram|smi|smil)',
);
if (isset($_SERVER['SCRIPT_NAME'])) {
$opts['selfname']=$_SERVER['SCRIPT_NAME'];
}
$opts['real_songdir']=preg_replace('/\/\/+/', '/', $DOCROOT . $opts['songdir']);
$songs = getSongs($opts['real_songdir']);
$cmp_funcs = array(
'artist' => 'cmp_artist',
'title' => 'cmp_title',
);
if (isset($_REQUEST['sort']) && $cmp_funcs[$_REQUEST['sort']] ) {
$opts['sort'] = $_REQUEST['sort'];
}
$cmp_func=$cmp_funcs[$opts['sort']];
if (isset($_REQUEST['dir'])) {
switch ($_REQUEST['dir']) {
case 'up':
case 'a':
case 'ascend':
case 'ascending':
break;
case 'down':
case 'd':
case 'descend':
case 'descending':
$opts['sortdir'] = -1;
break;
}
}
usort($songs, $cmp_func);
?>
<html>
<head>
<title>Boombox Songlist</title>
<link REL='stylesheet' TYPE='text/css' HREF='/css/main.css' />
<style type='text/css'>
td {
margin: 15px;
padding: 0px 15px;
}
</style>
<script type='text/javascript'>
document.setGlobals = function () {
var wpd = window.parent.document;
if (wpd.player) {
this.player = wpd.player;
} else {
this.player = wpd.getPlayer();
}
this.play = function (url) {
if (null != this.player) {
this.player.DoStop();
this.player.SetSource(url);
this.player.DoPlay();
} else {
alert("There's no media player.");
}
}
}
</script>
</head>
<!--
document.setGlobals is called both here and boombox.php, as either may
be the last to load
-->
<body onload='document.setGlobals()'>
<table>
<tr>
<th><a href="<?=selflink()?>">Artist</a></th>
<th><a href="<?=selflink(array('sort' => 'title'))?>">Title</a></th>
</tr>
<?php
foreach ($songs as $song) {
?>
<tr>
<td><a href=<?= playlink($song) ?>><?=$song['artist']?></a></td>
<td><a href=<?= playlink($song) ?>><?=$song['title']?></a></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
<?php
function getSongs($root) {
global $opts;
foreach (glob(preg_replace('/\/*$/', '', $root) . '/*') as $dir) {
while (is_link($dir)) {
$dir=preg_replace('/\/*$/', '', readlink($dir));
}
if (is_dir($dir)) {
if ('//' == ($ignore = get_ignore($dir))) continue;
foreach (glob($dir . '/*') as $file) {
if (is_audio($file)
&& !($ignore && preg_match($ignore, basename($file))))
{
$songs[] = songInfoFromPath($file);
}
}
}
}
return $songs;
}
function get_ignore($dir) {
$ignore = '';
if (file_exists($dir . '/.ignore')
&& $ign_file = fopen($dir . '/.ignore', 'r'))
{
$ignore = trim(fgets($ign_file));
fclose($ign_file);
if ($ignore) {
$ignore = preg_replace('/^\\/?|\\/?$/', '/', $ignore);
} else {
//.ignore has empty ignore spec, so ignore all
$ignore = '//';
}
}
return $ignore;
}
function cmp_artist($a, $b) {
return compare($a, $b, array('artist', 'title'));
};
function cmp_title($a, $b) {
return compare($a, $b, array('title', 'artist'));
};
function compare($a, $b, $fields) {
global $opts;
foreach ($fields as $field) {
if (isset($a[$field]) && isset($b[$field])) {
preg_match('/^(?:the |a )?(.*)$/i', $a[$field], $matches['a']);
preg_match('/^(?:the |a )?(.*)$/i', $b[$field], $matches['b']);
$diff = strnatcasecmp($matches['a'][1], $matches['b'][1]);
if ($diff) {
return $diff * $opts['sortdir'];
}
}
}
return 0;
}
function is_audio($fname) {
global $opts;
return preg_match('/\.'.$opts['audioext_RE'].'$/', $fname);
}
function songInfoFromPath($fname, $spacify = -1) {
global $opts;
if ($spacify < 0) {
$spacify = $opts['spacify'];
}
preg_match('/([^\/]*)\/([^\/]*)\.'.$opts['audioext_RE'].'$/', $fname, $matches);
$song = array(
'url' => $opts['songdir'] . $matches[0],
'artist' => $matches[1],
'title' => $matches[2],
);
// insert spaces before capital letters?
if ($spacify) {
foreach (array('artist') as $field) {
$song[$field] = preg_replace('/([a-z])([A-Z])/', '$1 $2', $song[$field]);
}
}
return $song;
}
function selflink($params = array()) {
global $opts;
if ($opts['sortdir'] > 0
&& (!isset($params['sort']) || $params['sort'] == $opts['sort']))
{
$params['dir'] = 'd';
}
if (count($params)) {
foreach ($params as $name => $val) {
$pars[] = $name . '=' . $val;
}
$params = '?' . implode('&', $pars);
} else {
$params = '';
}
return $opts['selfname'] . $params;
}
function url_ord($ch) {
return sprintf("%%%02X", ord($ch[0]));
}
function safify_url($url) {
$url = preg_replace('/([\\\\"\'])/', '\\\\$1', $url);
return preg_replace_callback('/[ -\'`"*:-@\\\\^]/', 'url_ord', $url);
}
function playlink($song, $dfltdir = '') {
global $opts;
$url = $song['url'];
if ('' == $dfltdir) {
$artist = $song['artist'];
if ($opts['spacify']) {
$artist = preg_replace('/([a-z]) ([A-Z])/', '$1$2', $artist);
}
$dfltdir = $opts['songdir'] . $artist . '/';
}
$dfltdir = preg_replace('/^\/*|\/*$/', '/', $dfltdir);
if ($url{0} != '/') {
$url = $dfltdir . $url;
}
$url = safify_url($url);
$url = $opts['scheme'] . '://' . $_SERVER['SERVER_NAME'] . $url;
//return "javascript:play('$url')";
return "'javascript:document.play(\"$url\")'";
}
?>
|
Last edited by kanenas on Thu Jan 20, 2005 5:04 pm; edited 8 times in total |
|
Solaris
Joined: 25 Dec 2004 Posts: 5 Location: The Fortress
|
Posted: Sun Jan 09, 2005 5:26 pm |
|
|
|
Kanenas, thank you so much for helping me. I will try to get this going and let you know how it turned out. If I have any question, I will return here for your help, if that's o.k.
Again, thanks so much! I really appreciate the time you spent on this.
~Solaris |
|
Solaris
Joined: 25 Dec 2004 Posts: 5 Location: The Fortress
|
Posted: Sun Jan 09, 2005 5:38 pm |
|
|
|
O.K, I have a couple of questions:
1) do I edit the file.php by adding my song info, and if so where do I begin?
2) once that's been done, where in the boombox.html do I place the file.php?
Thanks! |
|
kanenas

Joined: 14 Dec 2004 Posts: 191
|
Posted: Mon Jan 10, 2005 3:12 pm How files.php gets song information |
|
|
|
| Solaris wrote: |
O.K, I have a couple of questions:
1) do I edit the file.php by adding my song info, and if so where do I begin?
|
The song information can be stored in files.php, an external file which files.php parses, a database, in the directory structure or (possibly) be read from the files themselves. Which course to take depends, among other things, on how often songs will be added and removed. The "correct" locations to store the information are a database (but then you have to set up and administer one), the directory structure or the audio files, in which case you need a PHP package to read the information.
The second simplest alternative is to use the pathname of each file to store song information; it's a close second to storing the information in files.php. Choose some directory to be the root for song files (e.g. ~www/htdocs/songs or whatnot [as FortWayneHipHop.com seems to be running a flavor of Unix]); let's call it $songroot. Create a sub-directory for each artist. Song files are thus named "$songroot\$artist\$title.$ext", where $ext is the extension appropriate for the media type. To get song information files.php would enumerate subdirectories of $songroot and files in each subdirectory to get the artist & title.
For the database option, you could use a dbm-style database and PHP's dba extention; this option would be about as much effort as parsing an external file. You could also install MySQL (which requires more effort and overhead) and use PHP MySQL Functions or the Improved MySQL Extension.
If song information is to be retrieved the audio files, find out in what format the information is stored and check if there is a PHP package that handles the format. For instance, if the songs are mp3s, you can use ID3 functions (if the id3 package isn't installed, you can get it from PECL). A list of the files themselves still needs to be stored somewhere, unless they are all stored (and only they are stored) in the same branch of the filesystem.
Having files.php parse a file for song information is programmatically slightly more complex than storing the information in inifile format using dba, so there's no great reason to choose this approach.
As for storing the information in files.php, this is the simplest option but isn't recommended. It's only slightly simpler than using a directory structure which reflects the song information.
| Solaris wrote: |
2) once that's been done, where in the boombox.html do I place the file.php?
Thanks! |
files.php is already loaded in the iframe.
One more note on supporting other media players: DoPlay (and DoStop) are RealPlayer-specific. Either define these methods for the player object for non-RP players, or (my personal recommendation) define 'play' and 'stop' methods for the RealPlayer object. |
|
Solaris
Joined: 25 Dec 2004 Posts: 5 Location: The Fortress
|
Posted: Mon Jan 10, 2005 7:57 pm |
|
|
|
Good lawd, I'm soooo lost!
I'm sorry Kanenas, but I can't even begin to understand all that you've posted.
Thanks so much for your time and effort. Hopefully, someone will be able to use your information for their site.
I hope you don't get too upset at me for not attempting to use your information. I'm afraid I'll truly mess it up. Thanks again....sincerely! |
|
kanenas

Joined: 14 Dec 2004 Posts: 191
|
Posted: Wed Jan 12, 2005 4:41 pm Not to worry |
|
|
|
Not to worry, for I wrote a test script while researching the problem. The source for files.php has been updated with the new script, slightly cleaned up. Set the default $DOCROOT (only needed if running this script from the command line, but still a good thing to do), and $opts['songdir'] to the virtual directory (i.e. in webspace) containing the artists directories (set to '/songs/'). Stick all the songs for each artist in his/her/their directory. That should be it. The only drawback to this approach as implemented is limitations to filenames apply to artist & titles (e.g. length limitations, invalid characters).
Because I tend to get feature happy, it can sort in ascending and descending order by either artist or title and (at your discretion) insert spaces between lower and upper case letters in the artist name (so a directory named 'DrDre' gets translated to the artist name 'Dr Dre') and has an 'ignore' feature to disable listing of artists & songs.
EDITED: Expanded files.php moved to 2nd message ("Object communication across iframe.").
Last edited by kanenas on Thu Jan 20, 2005 4:18 pm; edited 2 times in total |
|
kanenas

Joined: 14 Dec 2004 Posts: 191
|
Posted: Fri Jan 14, 2005 4:00 pm Bugfix |
|
|
|
EDITED: This message originally held edit information on source code for files.php in above message ("Not to worry") which is no longer relevant.
Last edited by kanenas on Thu Jan 20, 2005 4:21 pm; edited 1 time in total |
|
Solaris
Joined: 25 Dec 2004 Posts: 5 Location: The Fortress
|
Posted: Mon Jan 17, 2005 7:24 pm |
|
|
|
I can't set the player type to anything other than RealPlayer because my hosting company only hosts RealMedia files. So, what do I need to remove from the code you provided?
Also, I still really don't know where to begin.  |
|
kanenas

Joined: 14 Dec 2004 Posts: 191
|
Posted: Thu Jan 20, 2005 5:01 pm There's not much more to do. |
|
|
|
I've edited boombox.php and files.php in the original reply. At this point, all you should need to do is drop boombox.php and files.php into the same directory, optionally change a few settings, and create the directories to hold songs. In the document root on the web server, create a directory called 'songs'. In that directory, create a sub-directory for each artist. Store all the songs for an artist in his or her directory.
That will give you a plain boombox, so you should probably add style information. Both boombox.php and files.php link to '/css/main.css', so that's one place you could stick style. You have your own site design; I'll leave the rest of the graphic design considerations to you. |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
|