Jump to content

A way to play sound files at random places, say halfway through?


reportingsjr

Recommended Posts

Well my STLP (Student Technology Leadership Program) teacher wanted to have a radio type thing on the web and it would be in one hour segements. I have no problem getting the file to play if the time is inbetween say 4 pm and 5 pm, but is there a way so that if the radio show starts at 4 pm, and the user starts listening at 3:24 pm that I can play the sound file 23 minutes and x seconds into it? So that way its like a radio in your car, and it doesnt just start at the beginning every time.Would this require flash or something like that? I hope there is a way to do this... Thanks!!

Link to comment
Share on other sites

Well my STLP (Student Technology Leadership Program) teacher wanted to have a radio type thing on the web and it would be in one hour segements. I have no problem getting the file to play if the time is inbetween say 4 pm and 5 pm, but is there a way so that if the radio show starts at 4 pm, and the user starts listening at 3:24 pm that I can play the sound file 23 minutes and x seconds into it? So that way its like a radio in your car, and it doesnt just start at the beginning every time.Would this require flash or something like that? I hope there is a way to do this... Thanks!!
I'm sure you could do this with some long JS code. I'll work on a "sketch" for you.
Link to comment
Share on other sites

JS? I would've thought you'd use PHP and a database... could use JS though OKay, had a think about it, and this is how I'd do it: You have 60 1-minute-long sound files, and when you load the page a php script will find out how long into the "show" you are, and start playing from the nearest minute. You'd use JavaScript to play the next file after the current one has finished.

Link to comment
Share on other sites

The main thing is getting the file to play 24 minutes, or however long into the file. So if it starts at 4 pm, and you log on at 4:03 pm, it will automatically start at 3 minutes into the file.I would love if this is possible!

Link to comment
Share on other sites

The main thing is getting the file to play 24 minutes, or however long into the file. So if it starts at 4 pm, and you log on at 4:03 pm, it will automatically start at 3 minutes into the file.I would love if this is possible!
:):):) I thought you meant you wanted a sound file that would start playing at any given time, like 5:00. Well, I will do some research on this to see what I can find to help you. :blink:
Link to comment
Share on other sites

You can definately do it with Flash. I don't think you'll find another way to do it though, because Javascript doesn't have anything to do with the sound, Javascript doesn't play anything. It's the player on the client's PC, and I don't think there's any way to tell it to start at a specific point, not to mention that it would be a pain to work across all platforms the same way. But Flash can do it, if you have an audio stream embedded in the Flash, you can just jump to a specific frame. You can even make the movie 1 frame per second (won't look any good for animation, so no button effects), and then just skip forward that many seconds. You can also have a timer that just displays the current frame number, divided into hours and minutes.

Link to comment
Share on other sites

It will be a static file already produced, and it will be an mp3. So how might I do this? I dont think I have access to flash, but I can have access to it at my house (soon).Could I just make a flash file where you have the file on the server, and tell it to start running that sound file at 4:00 pm and then it will do everything else automatically? I dont want to have to make a new flash file for every different broadcasting.And about this windows thing, what exactly is this?Everything sounds good so far! Thanks for the help now! I just need to get it working :).

Link to comment
Share on other sites

Could I just make a flash file where you have the file on the server, and tell it to start running that sound file at 4:00 pm and then it will do everything else automatically? I dont want to have to make a new flash file for every different broadcasting.
You can do whatever you want, as long as you know how to write the code to do it.
Link to comment
Share on other sites

dorothy: No I havent, could you provide and info link?Steve: Thats the thing though lol, I dont know how to code flash/actionscript! :), so the real question is could you do this for me? I would be very grateful!

Link to comment
Share on other sites

oh :).This is what I would need it to do though (If you could quickly explain please?):For admin side or whatever have this-file: [file name (broadcast1.mp3)]play on: [date (9/18/06 9:00 pm)]So then at 9 pm on september the 18th it will start playing that, and if someone visits the page at 9:23 pm it will be playing 23 minutes into the file.So, ihow long would this take?

Link to comment
Share on other sites

The code for loading the sound itself and playing it isn't very hard, but there is extra time for the interface of the player, a stop button, volume control, time display, etc. For loading and playing the sound, Flash 8 includes a Sound object, with a method that loads an MP3 (which you can stream), and a method which starts the sound, at an optional second offset. This is the example code from Flash 8 help, with some minor modifications by me:

this.createTextField("status_txt", this.getNextHighestDepth(), 0,0,100,22);// create a new Sound objectvar my_sound:Sound = new Sound();// if the sound loads, play it; if not, trace failure loadingmy_sound.onLoad = function(success:Boolean) {	if (success) {	start_at = 60; //seconds	my_sound.start(start_at);	status_txt.text = "Sound loaded";	} else {	status_txt.text = "Sound failed";	}};// load the soundmy_sound.loadSound("song1.mp3", true); // true makes it streaming

There are other methods to stop the sound, set the volume, load song information (ID3 info), set a callback when the sound completes, get the duration, get the total bytes, get the bytes loaded, etc.For determining the time, there is a Date object that you can use to get the number of milliseconds since January 1, 1970 (the Unix epoch timestamp), and you can use that to determine the offset to start at. You can access the URL by using the this._url property, and you can parse it up to get the querystring variables to determine the time that it should start at. You might need to check for a negative value before you start playing (if they click on the link before it is supposed to start), and have a timer that will start it automatically at the specified time. But, you are going off the client PC's clock, so if they are in a different timezone it wouldn't work. In that case, you would need a file on the server that you could query that would return the current timestamp that you can compare against, so that you run off the server's time.Hopefully that gives you a start. There is plenty of information on each of these items in the Flash help files.

Link to comment
Share on other sites

Well thank you very much! But I dont have flash =\.Ill see what I can do. Im actually working on a game right now. I have some errors in that that are a big ol' pain! Anyways, thanks again!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...