With the help of :
Image

Great Service, Support, Prices ! THE place to rent a good server ! Created by some from ex "mysTix" well known DoD:S Team
IMPORTANT !!!!
Need volonteer to store the website and keep the good job !!!!
I cannot maintain the website anymore.. Thanks !!
Contact by Steam please !

Je cherche un volontaire pour héberger le site et conserver le travail énorme fait par tous !
Je n'ai plus le temps de faire ça ! Merci !!!
Contactez-moi par Steam !

Need Help with php mp3 streaming player code

The first place to post ! Thanks !
Post Reply
User avatar
vintage
Site Admin
Posts: 125
Joined: Thu Nov 19, 2015 7:47 am
Location: France

Need Help with php mp3 streaming player code

Post by vintage » Sat Feb 20, 2016 8:45 am

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...
Right behind you ! ^^
User avatar
Ben
Posts: 34
Joined: Sat Nov 21, 2015 4:27 pm
Contact:

Re: Need Help with php mp3 streaming player code

Post by Ben » Sat Feb 20, 2016 9:48 am

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
User avatar
vintage
Site Admin
Posts: 125
Joined: Thu Nov 19, 2015 7:47 am
Location: France

Re: Need Help with php mp3 streaming player code

Post by vintage » Sun Feb 21, 2016 5:35 pm

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.
Right behind you ! ^^
User avatar
MihailM
Posts: 49
Joined: Mon Dec 28, 2015 1:39 pm
Location: Russia
Contact:

Re: Need Help with php mp3 streaming player code

Post by MihailM » Tue Feb 23, 2016 9:24 pm

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!
https://dayofdefeat.ucoz.net/ - Russian DOD:s site
User avatar
vintage
Site Admin
Posts: 125
Joined: Thu Nov 19, 2015 7:47 am
Location: France

Re: Need Help with php mp3 streaming player code

Post by vintage » Wed Feb 24, 2016 8:12 am

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 !
Right behind you ! ^^
User avatar
MihailM
Posts: 49
Joined: Mon Dec 28, 2015 1:39 pm
Location: Russia
Contact:

Re: Need Help with php mp3 streaming player code

Post by MihailM » Wed Feb 24, 2016 9:10 am

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.
https://dayofdefeat.ucoz.net/ - Russian DOD:s site
User avatar
vintage
Site Admin
Posts: 125
Joined: Thu Nov 19, 2015 7:47 am
Location: France

Re: Need Help with php mp3 streaming player code

Post by vintage » Sat Feb 27, 2016 7:09 am

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:
Right behind you ! ^^
User avatar
vintage
Site Admin
Posts: 125
Joined: Thu Nov 19, 2015 7:47 am
Location: France

Re: Need Help with php mp3 streaming player code

Post by vintage » Fri Mar 04, 2016 10:34 am

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 : :)
Right behind you ! ^^
Post Reply