Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411558 Posts in 69384 Topics- by 58443 Members - Latest Member: junkmail

May 03, 2024, 11:08:55 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Looping sounds issue
Pages: [1]
Print
Author Topic: Looping sounds issue  (Read 1251 times)
Craig Stern
Level 10
*****


I'm not actually all that stern.


View Profile WWW
« on: March 31, 2010, 10:24:12 PM »

So, my looping sound code is ddriving me nuts. It works perfectly when I test it by building in the Flash IDE using Ctrl + Enter, but the second I try running the game in a standalone player, looped sounds either don't loop or don't play. I'm at my wits' end trying to figure out why it works in the IDE player but not in a standalone projector.

Below is my music code: it checks the name of the track to be loaded against an array that contains the music's location, then loads the appropriate mp3 from that location and tells it to loop (minus 50 milliseconds off the front and back end to prevent popping).

Code:
function playMusic () {

Music.stop();

if (musicOn == true && currTrack !== "") {

for (i = 0; i < 50; i++) {
if (currTrack == songIndex[i][0]) {
targetSongURL = songIndex[i][1];
}
}

Music = new Sound();
Music.loadSound(targetSongURL, true);

//Looping code
var leader:Number = 50;    // milliseconds gap at the start of the mp3
var follower:Number = 50;  // milliseconds gap at the end of the mp3
var placeToStop:Number;

Music.onLoad = function(){
Music.start();
placeToStop = Music.duration - follower; //tell it where to loop

// run interval to constantly check the position of the mp3
// and restart after the initial mp3 gap.
var intervalVal:Number = setInterval( checkForLooping , 5 ); //run checkForLooping every 5 milliseconds

function checkForLooping():Void{
if (Music.position > placeToStop) { //if it's past the loop point
Music.stop();
Music.start(leader / 1000); //restart 50 milliseconds in
}
}

}
}

}

Any ideas why this would work in the IDE player but not in the standalone player? (And yes, before anyone says anything, this is AS2. And yes, I know AS2 sucks.)
Logged

Rob Lach
Level 10
*****



View Profile WWW
« Reply #1 on: March 31, 2010, 11:10:28 PM »

Hey, did you know that is AS2 and AS2 sucks?

Jokes aside, what do you mean by not looping? Are they not lining up or is there popping or something of that sort.
Logged

bateleur
Level 10
*****



View Profile
« Reply #2 on: March 31, 2010, 11:27:14 PM »

Quote
Any ideas why this would work in the IDE player but not in the standalone player?

It looks like it should work, but 5ms is pretty frequent for firing callbacks (on AS2, which is slow as a dog that's been stapled to the carpet). You might want to turn that down to 20ms for testing purposes, just to see if that's the source of the problem.

Failing that, put some visual indicator on screen that tells you the current state of the timer and how many times it's triggered your loop code.
Logged

jotapeh
Level 10
*****


View Profile
« Reply #3 on: April 01, 2010, 06:07:00 AM »

slow as a dog that's been stapled to the carpet

WTF

just.. ow.
Logged
Craig Stern
Level 10
*****


I'm not actually all that stern.


View Profile WWW
« Reply #4 on: April 01, 2010, 07:32:31 AM »

Are they not lining up or is there popping or something of that sort.

No--I mean the track plays once and then stops, and never restarts.

I've tracked the workings of the function using trace(), and it works fine in the IDE player. Of course, the standalone player doesn't show anything when trace is run. I'll try using a visual indicator.
Logged

Craig Stern
Level 10
*****


I'm not actually all that stern.


View Profile WWW
« Reply #5 on: April 03, 2010, 03:12:00 PM »

Yeah, the visual indicator showed nothing either. I moved the interval as high as 25 milliseconds, and that didn't help things.

So I switched from using the interval to just using an onSoundComplete function, and it works fine now. The downside to using onSoundComplete for this function is that it doesn't get rid of any silence at the tail end of the track--it only bypasses silence at the start. For whatever reason, though, it seems to get the job done with the mp3s I'm using, so I won't complain. Smiley
« Last Edit: April 04, 2010, 11:14:11 AM by Craig Stern » Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic