/    Sign up×
Community /Pin to ProfileBookmark

MP3 Streaming Script

I’m using JW Media Player to stream mp3 files.

Their forums suggest my use of the following script to avoid mp3 file caching …

[code=php]header(‘content-type: audio/mpeg’);
header(‘cache-control: no-store, must-revalidate’);
header(‘expires: sun, 06 oct 1974 21:00:00 gmt’);

$file_source = $_GET[‘source’];
$file_bandwidth = $_GET[‘bandwidth’];
$file_location = ‘audio/’.$file_source.’_’.$file_bandwidth.’.mp3′;

header(‘content-length: ‘.filesize($file_location));

$file_pointer = fopen($file_location, ‘rb’);

while (!feof($file_pointer)) {
echo(fread($file_pointer, 16384));
}

fclose($file_pointer);[/code]

I then use the following variable in my .swf embedding code …

[CODE]s2.addVariable(‘file’, encodeURIComponent(‘index.php?display=audio&source=’ + track + ‘&bandwidth=’ + bandwidth));
s2.addVariable(‘type’, ‘mp3’);[/CODE]

All of this is working but I have two questions / concerns.

1) I can access the audio file directly by typing “http://localhost/index.php?display=audio&source=somesong&bandwidth=hiband” into the browser address bar. I’d like to disable this possibility so that only the intended page can access/embed the stream. The page and the script are both located in the same php file, where one calls upon the other. How can I protect the stream location?

2) Sometimes, my overall javascript/php approach is causing audio to load much more slowly than before. I don’t know much about the commands being used in these scripts, so I’m wondering if there’s a way to keep things streaming at a normal pace. Ideas? Observations? Could it be that my use of “encodeURIComponent” in the javascript or the port which is referenced by the php code?

Thanks in advance.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@iltloOct 27.2007 — Ok this is like the red neck way of getting audio streaming, but:

Just upload it as a video to youtube, you can make it just black in windows movie maker. Then embed it on the site, but make it 1 px high and 1 px wide. It loads extremely fast, but the problem is you can't adjust the volume etc.

:rolleyes:
Copy linkTweet thisAlerts:
@robindeanauthorOct 27.2007 — Thanks for the effort ... but oh HELL no. :p

Anyone with the patience to make sense of my questions?
Copy linkTweet thisAlerts:
@robindeanauthorOct 28.2007 — Let me put this another way,

I have a javascript which uses "encodeURIComponent" to load a file that is generated via php.

I want for the php that is being loaded to ONLY be loaded by the page with the javascript in it. I'm hoping to do something to the php script which says "if the requesting document's url = my page with javascript, go ahead. Otherwise, redirect."

How do I do this?
Copy linkTweet thisAlerts:
@rootOct 28.2007 — I would assume that streaming would be similar to a forced file download.
×

Success!

Help @robindean spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...