1
mjz55
How can play a short audio clip when web site opens?
  • 2007/7/27 1:33

  • mjz55

  • Quite a regular

  • Posts: 298

  • Since: 2007/1/18


I'm using XOOPS 2.0.16. I would like a short audio clip (talking) playing when site opens. Is this possible and if so, how?

2
ewonline
Re: How can play a short audio clip when web site opens?
  • 2007/7/28 4:58

  • ewonline

  • Not too shy to talk

  • Posts: 198

  • Since: 2004/11/17


Yes its possible. I assume you want this on the homepage?
Edit your index.php and add the code. I would actually recommend putting your audio file into a flash movie and then embedding that on the page. Its more likely the user has flash player than quicktime or windows media player.
Resized Image

3
jmorris2
Re: How can play a short audio clip when web site opens?
  • 2007/7/28 6:11

  • jmorris2

  • Just popping in

  • Posts: 46

  • Since: 2007/4/17


<{php}> if ($_SERVER['REQUEST_URI'] == '/' && !isset( $_COOKIE['alreadycame'] ) ) {
    echo 
'';
    
setcookie'alreadycame''anything' );
    }
<{/
php}>


Plays 1x on the homepage only per browser session. Otherwise you'll annoy the hell out of people.

EDIT: BTW... Add that to your theme.html right before the tag.
The lights are on... nobody's home

4
Peekay
Re: How can play a short audio clip when web site opens?
  • 2007/7/28 9:15

  • Peekay

  • XOOPS is my life!

  • Posts: 2335

  • Since: 2004/11/20


Unless your host serves up your site using a Windows server + IIS, in which case replace:

$_SERVER['REQUEST_URI'];

with :

$_SERVER['SCRIPT_NAME'];


AFAIK the former doesn't work with IIS.
A thread is for life. Not just for Christmas.

5
mrphilong
Re: random img => random audio
  • 2007/7/29 4:04

  • mrphilong

  • Quite a regular

  • Posts: 351

  • Since: 2006/7/14


I found a php script that would display random image in a folder and would like to convert it to randomly select any file to use in:
<{php}> if ($_SERVER['REQUEST_URI'] == '/' && !isset( $_COOKIE['alreadycame'] ) ) {
    echo 
'';
    
setcookie'alreadycame''anything' );
    }
<{/
php}>


here is a script for random image, could someone with the knowledge of php please change it so it would pickup any file type in the folder.

/*

    AUTOMATIC IMAGE ROTATOR
    Version 2.2 - December 4, 2003
    Copyright (c) 2002-2003 Dan P. Benjamin, Automatic, Ltd.
    All Rights Reserved.

    http://www.hiveware.com/imagerotator.php
    
    http://www.automaticlabs.com/
    
    
    DISCLAIMER
    Automatic, Ltd. makes no representations or warranties about
    the suitability of the software, either express or
    implied, including but not limited to the implied
    warranties of merchantability, fitness for a particular
    purpose, or non-infringement. Dan P. Benjamin and Automatic, Ltd.
    shall not be liable for any damages suffered by licensee
    as a result of using, modifying or distributing this
    software or its derivatives.
    
    
    ABOUT
    This PHP script will randomly select an image file from a
    folder of images on your webserver.  You can then link to it
    as you would any standard image file and you'll see a random
    image each time you reload.
    
    When you want to add or remove images from the rotation-pool,
    just add or remove them from the image rotation folder.


    VERSION CHANGES
    Version 1.0
        - Release version
    
    Version 1.5
        - Tweaked a few boring bugs
    
    Version 2.0
        - Complete rewrite from the ground-up
        - Made it clearer where to make modifications
        - Made it easier to specify/change the rotation-folder
        - Made it easier to specify/change supported image types
        - Wrote better instructions and info (you're them reading now)
        - Significant speed improvements
        - More error checking
        - Cleaner code (albeit more PHP-specific)
        - Better/faster random number generation and file-type parsing
        - Added a feature where the image to display can be specified
        - Added a cool feature where, if an error occurs (such as no
          images being found in the specified folder) *and* you're
          lucky enough to have the GD libraries compiled into PHP on
          your webserver, we generate a replacement "error image" on
          the fly.
        
    Version 2.1
        - Updated a potential security flaw when value-matching
          filenames

    Version 2.2
        - Updated a few more potential security issues
        - Optimized the code a bit.
        - Expanded the doc for adding new mime/image types.

        Thanks to faithful ALA reader Justin Greer for
        lots of good tips and solid code contribution!


    INSTRUCTIONS
    1. Modify the $folder setting in the configuration section below.
    2. Add image types if needed (most users can ignore that part).
    3. Upload this file (rotate.php) to your webserver.  I recommend
       uploading it to the same folder as your images.
    4. Link to the file as you would any normal image file, like this:

            

    5. You can also specify the image to display like this:

            
        
        This would specify that an image named "gorilla.jpg" located
        in the image-rotation folder should be displayed.
    
    That's it, you're done.

*/




/* ------------------------- CONFIGURATION -----------------------


    Set $folder to the full path to the location of your images.
    For example: $folder = '/user/me/example.com/images/';
    If the rotate.php file will be in the same folder as your
    images then you should leave it set to $folder = '.';

*/


    
$folder '.';


/*    

    Most users can safely ignore this part.  If you're a programmer,
    keep reading, if not, you're done.  Go get some coffee.

    If you'd like to enable additional image types other than
    gif, jpg, and png, add a duplicate line to the section below
    for the new image type.
    
    Add the new file-type, single-quoted, inside brackets.
    
    Add the mime-type to be sent to the browser, also single-quoted,
    after the equal sign.
    
    For example:
    
    PDF Files:

        $extList['pdf'] = 'application/pdf';
    
    CSS Files:

        $extList['css'] = 'text/css';

    You can even serve up random HTML files:

        $extList['html'] = 'text/html';
        $extList['htm'] = 'text/html';

    Just be sure your mime-type definition is correct!

*/

    
$extList = array();
    
$extList['gif'] = 'image/gif';
    
$extList['jpg'] = 'image/jpeg';
    
$extList['jpeg'] = 'image/jpeg';
    
$extList['png'] = 'image/png';
    

// You don't need to edit anything after this point.


// --------------------- END CONFIGURATION -----------------------

$img null;

if (
substr($folder,-1) != '/') {
    
$folder $folder.'/';
}

if (isset(
$_GET['img'])) {
    
$imageInfo pathinfo($_GET['img']);
    if (
        isset( 
$extListstrtolower$imageInfo['extension'] ) ] ) &&
        
file_exists$folder.$imageInfo['basename'] )
    ) {
        
$img $folder.$imageInfo['basename'];
    }
} else {
    
$fileList = array();
    
$handle opendir($folder);
    while ( 
false !== ( $file readdir($handle) ) ) {
        
$file_info pathinfo($file);
        if (
            isset( 
$extListstrtolower$file_info['extension'] ) ] )
        ) {
            
$fileList[] = $file;
        }
    }
    
closedir($handle);

    if (
count($fileList) > 0) {
        
$imageNumber time() % count($fileList);
        
$img $folder.$fileList[$imageNumber];
    }
}

if (
$img!=null) {
    
$imageInfo pathinfo($img);
    
$contentType 'Content-type: '.$extList$imageInfo['extension'] ];
    
header ($contentType);
    
readfile($img);
} else {
    if ( 
function_exists('imagecreate') ) {
        
header ("Content-type: image/png");
        
$im = @imagecreate (100100)
            or die (
"Cannot initialize new GD image stream");
        
$background_color imagecolorallocate ($im255255255);
        
$text_color imagecolorallocate ($im0,0,0);
        
imagestring ($im255,  "IMAGE ERROR"$text_color);
        
imagepng ($im);
        
imagedestroy($im);
    }
}

?>

6
mjz55
Re: random img => random audio
  • 2007/8/1 14:05

  • mjz55

  • Quite a regular

  • Posts: 298

  • Since: 2007/1/18


Nobody, I had no luck. I also tried Peekay's idea too and no luck. I put it in my theme/theme.html, where you said. I tried the wav beforehand with wmp and it works. Any more ideas or what I may have done wrong?

7
Peekay
Re: random img => random audio
  • 2007/8/1 19:09

  • Peekay

  • XOOPS is my life!

  • Posts: 2335

  • Since: 2004/11/20


It's been a long time since I looked at 'onload' audio. Ewonline is right in that Flash offers the best cross-platform player. The best solution I can see at the moment is XSPF Player

http://musicplayer.sourceforge.net/

It uses Flash, plus an XML playlist to play MP3 file(s). It needs the Flash plugin version 7 or later, which most modern browsers should have (it plays in 'Epiphany' on Linux, so what more could you want!).

You can set it up to play an MP3 automatically on page load.
You can split your audio into several MP3 files and it will play them sequentially.
You can stick it in a XOOPS block.
Users can switch the audio off, or select files if you use the 'extended' version.

In the code below, replace 'example.com' with your website URL.

1) Download the 'slim' version 0.2.3.
2) Rename the folder 'xspf'.
3) Place the xspf folder in your XOOPS root.
4) Add MP3 file(s) to the folder (in this example 'intro1.mp3' and 'intro2.mp3').
5) Create an XSPF format playlist in a plain text editor, e.g.

xml version="1.0" encoding="UTF-8"?>

  
   
    http://www.example.com/xspf/intro1.mp3
    Text to be displayed for first file
   
   
    http://example.com/xspf/intro2.mp3
    Text to be displayed for second file
   
  


Save this as 'playlist.xspf' in the xspf folder.

Create a new block in XOOPS (HTML) and add the code:

<object type="application/x-shockwave-flash" width="100%" height="170"
data="http://www.example.com/xspf/xspf_player_slim.swf?playlist_url=http://www.example.com/xspf/playlist.xspf&autoplay=true">
<
param name="movie" 
value="http://www.example.com/xspf/xspf_player_slim.swf?playlist_url=http://www.example.com/xspf/playlist.xspf&autoplay=true" />
object>

Remember to make the block visible to the anonymous users group. Omit the 'autoplay' param if you don't want the audio to play when the page loads.

HTH

Tip: watch your 'x', 'f', 'p's and 's's when defining paths. It's a bit of a tongue twister.

This works in IE6 (now). However, Microsoft have done something really bizarre with later Internet Explorer upgrades which may stop any of this working.

Some info here
A thread is for life. Not just for Christmas.

8
Peekay
Re: random img => random audio
  • 2007/8/2 12:25

  • Peekay

  • XOOPS is my life!

  • Posts: 2335

  • Since: 2004/11/20


As a sidenote, like all Flash players this one does not like variable bitrate encoded (VBR) MP3s if they are below 128 kbps. I found it worked if the encoding was 128 or higher, but it appears the recommendation is not to use VBR.

Also, even if you use constant bitrate (CBR) the sample rate MUST be 44.1 or 22.5 khz. Apparently some MP3 encoders create hybrid sample rates. You'll know if it's wrong when your audio vocals sound like the chipmunks!

44100 khz - 128 or 96 kbps
22050 khz - 56 or 48 kbps
A thread is for life. Not just for Christmas.

9
mjz55
Re: random img => random audio
  • 2007/8/2 18:28

  • mjz55

  • Quite a regular

  • Posts: 298

  • Since: 2007/1/18


Peekay, I had no luck. The only thing that happens is the scrolling text in the newly created block in Xoops. I have no audio. I did the single bit rate at 128 for the mp3.

10
Peekay
Re: random img => random audio
  • 2007/8/2 20:58

  • Peekay

  • XOOPS is my life!

  • Posts: 2335

  • Since: 2004/11/20


Sorry, my fault. It appears IE on the PC has a problem with the empty 'image' tag I left in the playlist file. Just remove it (or add an image path). Modified playlist.xspf below (original above modified).

xml version="1.0" encoding="UTF-8"?>

  
   
    http://www.example.com/xspf/intro1.mp3
    Text to be displayed for first file
   
   
    http://example.com/xspf/intro2.mp3
    Text to be displayed for second file
   
  



Can you confirm if that works?
A thread is for life. Not just for Christmas.

Login

Who's Online

396 user(s) are online (267 user(s) are browsing Support Forums)


Members: 0


Guests: 396


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits