/    Sign up×
Community /Pin to ProfileBookmark

Use cookie load mp3

Hey guys,

Quick question. I want to load a short 500k mp3 upon loading of my site. However, I dont want it loaded all the time. I need to use a cookie Im assuming here. So basically it’ll load, play, and then wont reload again until the browser is closed and the page reloaded.

Any script to do this? Im not sure any other ways to do this. I guess I could embed the song, but I dunno if thats what I wanna do.

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@javaNoobieOct 07.2004 — Yes you are going to need the embed.
So basically it'll load, play, and then wont reload again until the browser is closed and the page reloaded.[/quote]
Might wanna give more detail here.
I want to load a short 500k mp3 upon loading of my site[/quote]
500k is big.:rolleyes: Make sure you add controls to control the music.
Copy linkTweet thisAlerts:
@chugger93authorOct 07.2004 — I have this javascript code that I found which basically loads another HTML page upon loadup

[code=php]
<SCRIPT LANGUAGE="JavaScript">
<!--
myWindow=window.open('','music','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=150,height=50');
self.focus();
myWindow.href = 'http://www.domain.com/yo/music.html';
if (!myWindow.opener) myWindow.opener = self;


//-->
</SCRIPT>[/code]


then in my [b]music.html[/b] file I have this

[code=php]
<embed src="swear.mp3" width="300" height="60" quality="high"></embed>[/code]


So basically you visit via the browser, http://www.domain.com/index93.html which upon visit loads the music.html pop up window.

My problem is....the stupid EMBED doesnt work. I get nothing but a blank page. No music loads. Any ideas? If you visit the music.html file directly though, it works!
Copy linkTweet thisAlerts:
@javaNoobieOct 07.2004 — try putting the href in the window.open() instead.
Copy linkTweet thisAlerts:
@Warren86Oct 07.2004 — chugger93:

This will play your clip just once every time the page is loaded.

<HTML>

<Body>

<BgSound Loop=1 Volume="-500" Src="swear.mp3">

</Body>

</HTML>
Copy linkTweet thisAlerts:
@chugger93authorOct 07.2004 — Javanoobie, what do u mean? can u give an example? new to javascript...

It still doesnt work, I dont wanna use BGSOUND. I dont want it playing per page load. I want it per browser session probably. Or even a button that says, do not show this window again, and sets a cookie

http://chugger.homeip.net/yo/index93.html
Copy linkTweet thisAlerts:
@Warren86Oct 07.2004 — Session cookie:

<HTML>

<Head>

<Script Language=JavaScript>

embedStr = "<Embed Src='swear.mp3' Width=0 Height=0>"

function setCookie(name, value) {
curCookie = name + "=" + value;
document.cookie = curCookie;
}

function getCookie(name) {
dc = document.cookie;
prefix = name + "=";
begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
} else
begin += 2;
end = document.cookie.indexOf(";", begin);
if (end == -1)
end = dc.length;
return unescape(dc.substring(begin + prefix.length,end));
}

function checkState(){

if (!getCookie('nMP3'))
{isGreeting.innerHTML = embedStr;
setCookie('nMP3',1)}
else {isGreeting.innerHTML = ""};
}

window.onload=checkState;


</Script>

</Head>

<Body>

<Div id='isGreeting'></Div>

</Body>

</HTML>
Copy linkTweet thisAlerts:
@chugger93authorOct 07.2004 — Thanks for the code warren, however it still doesnt work. I dunno whats wrong. If you visit that URL another popup window comes up, but nothing plays. Its very strange.
Copy linkTweet thisAlerts:
@Warren86Oct 07.2004 — Did you even try the code I posted? Exactly why do you need that popup window? Are you using it just to contain the .mp3? Oh, well. The truth is, I have no idea what in the heck you are trying to do. First it's this, then it's that, then there's an empty popup, and next, who knows? I give up. The code I posted plays the mp3 when the document is first loaded. It will not play again if the document is refreshed. I give up.
Copy linkTweet thisAlerts:
@chugger93authorOct 07.2004 — I want the popup window on pageload. The popup window itself contains the mp3 file to play.

What I want isn't confusing. You simply visit my homepage, and upon page load, a popup window should come up, in the background and begin playing the mp3. If you close the popup window (and in turn stop the song of course) then u can still manuever around my site without it coming back up until u revisit my homepage in another browser session.


I have ur code in my music.html file currently (which is my popup window)

Im saying it doesnt play when u visit that URL. Make sense?
Copy linkTweet thisAlerts:
@Warren86Oct 07.2004 — No, it doesn't make any sense. The code I posted is the MAIN page. If you want visitors to be able to stop the mp3 before it's finished, which I assume is the reason you have a pop up that the user can close, just change this line in the code I provided:

embedStr = "<Embed Src='swear.mp3' Width=0 Height=0>"

to this:

embedStr = "<Embed Src='swear.mp3' Width=70 Height=40>"

and the "Controls" will be visible, meaning, the user can click the "stop" button.

Other than this, I have nothing further to offer. I never told you to put my code into a popup window. It's the main file.
×

Success!

Help @chugger93 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...