Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

Display image for .wav file while running

images php coding issues or problems here.

Moderators: macek, egami, gesf

Display image for .wav file while running

Postby roopanimmagadda » Thu Mar 17, 2011 10:25 pm

I want to place waveform image while running a .wav file instead of default one
roopanimmagadda
New php-forum User
New php-forum User
 
Posts: 12
Joined: Wed Mar 16, 2011 4:42 am

Re: Display image for .wav file while running

Postby johnj » Sat Mar 19, 2011 8:04 am

where do you want to place this image? In a php code?
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Display image for .wav file while running

Postby roopanimmagadda » Sun Mar 20, 2011 9:22 pm

I want to run a audio file using PHP,By default something is playing as a view,their i want to place waveform image when a song is playing
roopanimmagadda
New php-forum User
New php-forum User
 
Posts: 12
Joined: Wed Mar 16, 2011 4:42 am

Re: Display image for .wav file while running

Postby johnj » Mon Mar 21, 2011 2:48 am

please post the code
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Display image for .wav file while running

Postby roopanimmagadda » Mon Mar 21, 2011 9:51 pm

<?php
ini_set("max_execution_time", "30000");

/**
* GENERAL FUNCTIONS
*/
function nadjiVrijednosti($byte1, $byte2){
$byte1 = hexdec(bin2hex($byte1));
$byte2 = hexdec(bin2hex($byte2));
return ($byte1 + ($byte2*256));
}

/**
* Great function slightly modified as posted by Minux at
* http://forums.clantemplates.com/showthread.php?t=133805
*/
function html2rgb($input) {
$input=($input[0]=="#")?substr($input, 1,6):substr($input, 0,6);
return array(
hexdec( substr($input, 0, 2) ),
hexdec( substr($input, 2, 2) ),
hexdec( substr($input, 4, 2) )
);
}

if (isset($_FILES["mp3"])) {

$filename = $_FILES["mp3"]["name"];
//$filename = "http://localhost/firstsight.wav";

$handle = fopen ($filename, "r");

//dohvacanje zaglavlja wav datoteke
$zaglavlje[] = fread ($handle, 4);
$zaglavlje[] = bin2hex(fread ($handle, 4));
$zaglavlje[] = fread ($handle, 4);
$zaglavlje[] = fread ($handle, 4);
$zaglavlje[] = bin2hex(fread ($handle, 4));
$zaglavlje[] = bin2hex(fread ($handle, 2));
$zaglavlje[] = bin2hex(fread ($handle, 2));
$zaglavlje[] = bin2hex(fread ($handle, 4));
$zaglavlje[] = bin2hex(fread ($handle, 4));
$zaglavlje[] = bin2hex(fread ($handle, 2));
$zaglavlje[] = bin2hex(fread ($handle, 2));
$zaglavlje[] = fread ($handle, 4);
$zaglavlje[] = bin2hex(fread ($handle, 4));

//bitrate wav datoteke
$peek = hexdec(substr($zaglavlje[10], 0, 2));

$bajta = $peek / 8;

//provjera da li se radi o mono ili stereo wavu
$kanala = hexdec(substr($zaglavlje[6], 0, 2));

if($kanala == 2){
$omjer = 40;
}
else{
$omjer = 80;
}

while(!feof($handle)){
$bytes = array();
//get number of bytes depending on bitrate
for ($i = 0; $i < $bajta; $i++){
$bytes[$i] = fgetc($handle);
}
switch($bajta){
//get value for 8-bit wav
case 1:
$data[] = nadjiVrijednosti($bytes[0], $bytes[1]);
break;
//get value for 16-bit wav
case 2:
if(ord($bytes[1]) & 128){
$temp = 0;
}
else{
$temp = 128;
}
$temp = chr((ord($bytes[1]) & 127) + $temp);
$data[]= floor(nadjiVrijednosti($bytes[0], $temp) / 256);
break;
}
//skip bytes for memory optimization
fread ($handle, $omjer);

}

// close and cleanup
fclose ($handle);
//unlink("$filename");

/**
* Image generation
*/

header("Content-Type: image/png");

// how much detail we want. Larger number means less detail
// (basically, how many bytes/frames to skip processing)
// the lower the number means longer processing time
define("DETAIL", 0.01);

// get user vars from form
$width = isset($_POST["width"]) ? (int) $_POST["width"] : 500;
$height = isset($_POST["height"]) ? (int) $_POST["height"] : 50;
$foreground = isset($_POST["foreground"]) ? $_POST["foreground"]: "brown";
$background = isset($_POST["background"]) ? $_POST["background"]: "blue";

// creat@e original image width based on amount of detail
$img = @imagecreatetruecolor(sizeof($data) / DETAIL, $height) or die('Cannot Initialize new GD image stream');

// fill background of image
list($r, $g, $b) = html2rgb($background);
imagefilledrectangle($img, 0, 0, sizeof($data) / DETAIL, $height,imagecolorallocate($img, 255, 255, 255));

// generate background color
list($r, $g, $b) = html2rgb($foreground);

// loop through frames/bytes of wav data as genearted above
for($d = 0; $d < sizeof($data); $d += DETAIL) {
// relative value based on height of image being generated
// data values can range between 0 and 255
$v = (int) ($data[$d] / 225 * 80);
// draw the line on the image using the $v value and centering it vertically on the canvas
imageline($img, $d / DETAIL, 0 + ($height - $v), $d / DETAIL,$height - ($height - $v), imagecolorallocate($img, 163, 168, 171));
}

// want it resized?
if ($width) {

// resample the image to the proportions defined in the form
$rimg = imagecreatetruecolor($width, $height);
imagecopyresampled($rimg, $img, 0, 0, 0, 0, $width, $height,sizeof($data) / DETAIL, $height);
imagepng($rimg);
imagedestroy($rimg);

} else {

// print out at it's raw width (size of $data / detail level)
imagepng($img);
imagedestroy($img);

}

} else {

?>

<form method="post" action="" enctype="multipart/form-data">

<p>MP3 File:<br />
<input type="file" name="mp3" /></p>

<p>Image Width:<br />
<input type="text" name="width" value="500" /></p>

<p>Image Height:<br />
<input type="text" name="height" value="50" /></p>

<p>Foreground Color: <small>(HEX/HTML color code)</small><br />
<input type="text" name="foreground" value="#FF0000" /></p>

<p>Background Color: <small>(HEX/HTML color code)</small><br />
<input type="text" name="background" value="#FFFFFF" /></p>

<p><input type="submit" value="Generate Waveform" /></p>

</form>

<?php

}
?>

By Using the above code I have generated waveform image

<embed src="firstsight.wav" height="100" widt="500"></embed>

By using above html i am running .wav file.Now i want to place waveform image as background while i am running this firstsight.wav
roopanimmagadda
New php-forum User
New php-forum User
 
Posts: 12
Joined: Wed Mar 16, 2011 4:42 am

Re: Display image for .wav file while running

Postby gandahar » Tue Mar 22, 2011 4:17 am

i think you'll have to create your own player and adapt it to the result you want
User avatar
gandahar
New php-forum User
New php-forum User
 
Posts: 112
Joined: Tue Mar 15, 2011 4:05 am

Re: Display image for .wav file while running

Postby johnj » Tue Mar 22, 2011 8:07 pm

"By using above html i am running .wav file.Now i want to place waveform image as background while i am running this firstsight.wav"

In the same html why don't you create a table, put this image as its background, at the same time use src="..." to run the .wav file?
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Display image for .wav file while running

Postby roopanimmagadda » Thu Mar 24, 2011 5:27 am

By placing "src" there is no use,i tried by using Div,table,param tags

Other than these ,is there any solution for custom background image
roopanimmagadda
New php-forum User
New php-forum User
 
Posts: 12
Joined: Wed Mar 16, 2011 4:42 am

Re: Display image for .wav file while running

Postby gandahar » Thu Mar 24, 2011 6:02 am

have you tried using layers ?

have you tried to use google to find a similar open source project to save time using a framework or a script and modify/adapt it to your needs ¿

look at this, perhaps you can copy and paste some peace of code :oops:
this is exactly what you want i think :
http://soundcloud.com/cyclop/tracks
User avatar
gandahar
New php-forum User
New php-forum User
 
Posts: 112
Joined: Tue Mar 15, 2011 4:05 am

Re: Display image for .wav file while running

Postby roopanimmagadda » Thu Mar 24, 2011 10:44 pm

Hey my task to add player sama as in soundcloud.com,for that reason first i have generated waveform image using audio file which is as in soundcloud,now i want to place image in player..

My task is to develop script for a player same as in soundcloud.com..

I am working on that now...
roopanimmagadda
New php-forum User
New php-forum User
 
Posts: 12
Joined: Wed Mar 16, 2011 4:42 am

Re: Display image for .wav file while running

Postby johnj » Fri Mar 25, 2011 7:56 pm

@roop..gadda

If your player is going to be viewed in a browser then the final output has to be in html,you have to use src,div, table etc - some of those tags. Of course you can use an intermediate solution (like Javascript or Flex) but still that has to be embedded into an html page. As far as I know there are no framework or scripts for placing a background image.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Display image for .wav file while running

Postby gandahar » Fri Apr 01, 2011 2:08 am

hi

another way is soundcloud api

you can use the soundcloud player 8)

http://soundcloud.com/developers
User avatar
gandahar
New php-forum User
New php-forum User
 
Posts: 112
Joined: Tue Mar 15, 2011 4:05 am

Re: Display image for .wav file while running

Postby roopanimmagadda » Mon Apr 04, 2011 10:20 pm

thanks for ur time..

Finally got the solution..

I have used Jplayer and in that i have placed my webform image while playing
roopanimmagadda
New php-forum User
New php-forum User
 
Posts: 12
Joined: Wed Mar 16, 2011 4:42 am

Re: Display image for .wav file while running

Postby gandahar » Wed Apr 06, 2011 5:15 am

please can you show us an example of the result you get ?

:D
User avatar
gandahar
New php-forum User
New php-forum User
 
Posts: 112
Joined: Tue Mar 15, 2011 4:05 am


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron