Page 1 of 1

Need Help with php mp3 streaming player code

Posted: Sat Feb 20, 2016 8:45 am
by vintage
Hi @ll !
If somebody can help with this...
I use a php player to stream sound via hidden motd to players.
So they don't need to download the sounds to their computer (a real unless time and a good way to have more than 300 sounds to play aactually ! :mrgreen: :mrgreen: ).

Where is the problem ?

If there is only 10/12 players all is fine and the stream is ok BUT when 18/20 players then the streaming is very long !
Sometimes it's possible to launch the sound and wait for 30 seconds to hear !!!
I think it's because the script send the sound to players and wait for all to get it to play the sound requested.....
(I don't know if what I write is clear enough.. :D )

Coming from here:
viewtopic.php?f=4&t=56&sid=4244fe3da819 ... c67d75278e

I've read somewhere that it's possible to send sound partially so it begin to play faster and the rest comes quick instead of streaming the whole sound (I only make some sounds no more than 1 minute 15/30 seconds -> ~ 1 Mo max)... Perhaps it's a solution ?

The plugin I use is fully inspirated by hiden url plugin...
To launch the sound, I just send via my adminmenu_custom:
http://adress_of_the_stock_music/index.php?id=Da_Da_Da.mp3

Here my php code (very basic... I know... but it run !)

Code: Select all

<?php
$dir = dirname($_SERVER['DOCUMENT_ROOT'])."/public_html/ziks";
$filename = $_GET['id'];
$file = $dir."/".$filename;

if(file_exists($file)){
    header('Content-type:audio/mpeg');
    header('Content-Disposition: filename="' . $filename);
    header('X-Pad: avoid browser bug');
    header('Cache-Control: public');
	header('preload: none');
    readfile($file);
}
?>
Can somebody help me to improve ????
And find a way to stream more quickly when there is many players ???? (more than 15 actually cause problem)

Thanks in advance !
I think this can help some admins server cause it use HTML5 and the motd browser is fully compatible with...

Re: Need Help with php mp3 streaming player code

Posted: Sat Feb 20, 2016 9:48 am
by Ben
Your idea to use motd to stream sounds to clients directly ingame is smart, but for bigger files and many players with different bandwidths problems cant be avoided... ill try something maybe this evening.

check also this code : https://forums.alliedmods.net/showthread.php?t=233549

Re: Need Help with php mp3 streaming player code

Posted: Sun Feb 21, 2016 5:35 pm
by vintage
Thanks Ben !
:)
I've read (somewhere) too that's it's possible to split the sounds into chunks.
So, the sound could be played at the first chunk streamed with no latency.
It's php and an API audio I think...

I confess that my php knowledge is limited... :mrgreen:

MihailM send me a plugin made by Root that does downloads to client with an URL.
The plugin is in Russian, I just need to change the phrases to english (near finish). Perhaps the code may help too...
I'll put this one on dodsplugins tomorrow or tuesday.

Re: Need Help with php mp3 streaming player code

Posted: Tue Feb 23, 2016 9:24 pm
by MihailM
And is not it easier to use, so this script http://www.flashmp3player.org/download.html to play music?
And like it is even free!

Re: Need Help with php mp3 streaming player code

Posted: Wed Feb 24, 2016 8:12 am
by vintage
Yes I use that before ! but now flash is not working anymore into motds !
Players have to install "flash for other browser" to listen sounds and even with many try, many where not able to listen.
Most from windows 10.

In fact, flash player is beginning to disapear because of too much security problems.
Many news say this on the web...

So the way to use HTML 5 seems to be a good alternative way because it's more powerfull !

Re: Need Help with php mp3 streaming player code

Posted: Wed Feb 24, 2016 9:10 am
by MihailM
Clearly there is to know. and that these things are not checked motd. Yes, and it seems a lot seyas banned motd, after the update.

Re: Need Help with php mp3 streaming player code

Posted: Sat Feb 27, 2016 7:09 am
by vintage
I improve a little bit my php code..
Sure if a good php coder take a look at this, he'll send me direct in Hell !!! :mrgreen: :mrgreen:

Seems to be a little bit better... But sure it's not finished !

here where I am:

Code: Select all

<?php
$dir = dirname($_SERVER['DOCUMENT_ROOT'])."/public_html/ziks";
$filename = $_GET['id'];
$file = $dir."/".$filename;
// $file_size  = filesize($file); -> for future use

if(file_exists($file)){
	header("Pragma: public");
	header("Expires: -1");
    header('Content-type:audio/mpeg');
    header('Content-Disposition: filename="' . $filename);
    header('X-Pad: avoid browser bug');
	header("Cache-Control: public, must-revalidate, post-check=0, pre-check=0");
	header('Content-Disposition: inline;');
	header('Content-Transfer-Encoding: binary');

	set_time_limit(0);
	$file_play = @fopen($file,"rb");
	while(!feof($file_play))
	{
	print(@fread($file_play, 1024*8));
	ob_flush();
	flush();
	}
}
?>
We have now more than 300 sounds ! A world record for a dod:s server ! hihihihi
But nothing to download by the client... So it stay cool !! Yeah
Just listen ? :P an example...
http://cdm.sons.mtxserv.fr/index.php?id ... Mah-Na.mp3
or
http://cdm.sons.mtxserv.fr/index.php?id=pompom.mp3
:geek:

Re: Need Help with php mp3 streaming player code

Posted: Fri Mar 04, 2016 10:34 am
by vintage
evolution of php code is now on gist...

https://gist.github.com/vintage59/c788cb1ae3a3a6b1414f

If someone can help.. I improve touch by touch... ;)

Have a nice day @ll : :)