PHP class to add your own sound effects to a webpage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ok, built my implementation of the soundManager javascript library, along with jQuery into my own PHP class to make it quick/easy to add real-time sound effects to a webpage.

Firstly, here's like 15 lines of PHP code that would implement a test version - of the three buttons, the first one is triggering using a jQuery event handler, second is implementing directly using the onclick tag attribute, and third one is just popping up an alert triggered via jQuery event:
<?php
//include class
require("./effects_class.php");
//implement instance of class
$soundEffects = new soundEffects();
//add 2 sound clips to class, using only file names and handle/variable names to then call them
$soundEffects->addSound($sFile="1.mp3", $sName="mySound1");
$soundEffects->addSound($sFile="2.mp3", $sName="mySound2");
//add extra JS to include inside jQuery document ready
$soundEffects->sExtraScript2Include = <<<JS
$("#btnTest").click( function(event) {
mySound1.play();
event.preventDefault();
});//end of btnTest click
$("#btnThree").click( function(event) {
alert("You clicked me too");
event.preventDefault();
});//end of btnThree click
JS;
//spit out all the relevant JS script/code
echo $soundEffects->spitOut();
?>

The generated code/HTML includes includes/link tags for all required code, and the class has public variables/values you can set with regards to storage folder for sound clip files, etc. as well.

And, here's the zip file to download including the class file, and the sample code (without above comments) etc.:
https://dl.dropboxusercontent.com/u/13327195/soundEffects_class.zip

Haven't implemented full on error handling in it thus far as such, but, if you want, give it a go, and let me know what you think, and, think this can handle both .MP3 and .wav sound clip files as such - might just have to make sure they'll work happily with all browsers, but anyway...might only really be happy with .mp3 files - need to test it a bit more myself.

And, this is the implementation that had tested somewhat across platform, on windows PC, with different browsers, linux machine, running firefox, mac PC's, my android phone, and some iPhones, etc.

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Database Programming]     [PHP Install]     [Kernel Newbies]     [Yosemite Forum]     [PHP Books]

  Powered by Linux