StopMusic always? (2.72)

Started by , Wed 21/04/2010 17:39:51

Previous topic - Next topic

m0ds

Hello there, I have a pretty simple question but I wouldn't know how to solve it. Couldn't see it mentioned elsewhere..

I need my game to StopMusic(); first whenever a PlayMusic function is called. Is there a way with code to achieve this, without having to go through my game putting StopMusic before every PlayMusic command?

Can something be added to the games rep_execute to recognise the PlayMusic command & intervene beforehand?

If so, please let me know! :)

Also, is there a way to make the engine fast forward or rewind through an MP3? Even if it makes an ugly sound as it does it? That would be really neat!

Thanks

NsMn

I don't quite understand. The music always stops whenever a new track is played through PlayMusic().

GarageGothic

QuoteAlso, is there a way to make the engine fast forward or rewind through an MP3?

You could probably fake it using SeekMP3PosMillis() to skip around the audio file, let it play for a few game loops, then jump another few milliseconds ahead. But as you say, it's not gonna sound pretty.

m0ds

Quote from: NsMn on Wed 21/04/2010 17:54:49
I don't quite understand. The music always stops whenever a new track is played through PlayMusic().

Haha yeah true, me too now. This is in my notes from playtesting the other day. I can't quite remember what it was doing but at the time this seemed to be the only method.

It may be video files. A certain music will play, then get interupted by a video with its own sound, then on return to the game, the music was starting again from the beginning, and that was bugging me. But there are some other instances of music that shouldn't be repeating that is. I'll have to play through again and find out a bit more, but you're right - a bit confusing generally because PlayMusic should stop it. However, I'm trying various soundtrack techniques so as dumb as it may seem - I definitely had a reason for writing it down :)

QuoteYou could probably fake it using SeekMP3PosMillis()

Thanks, I'll look into it!

m0ds

Quote from: GarageGothic on Wed 21/04/2010 18:10:10
QuoteAlso, is there a way to make the engine fast forward or rewind through an MP3?

You could probably fake it using SeekMP3PosMillis() to skip around the audio file, let it play for a few game loops, then jump another few milliseconds ahead. But as you say, it's not gonna sound pretty.

Hi dude, so how might I go about doing this? I've got a button, but I don't really know how on holding the button down make SeekMP3Pos move through the track. Seems pretty complex to me, any help is appreciated :)

Calin Leafshade

you'd have something like a timer..

in untested, bollocks code

Code: ags


(in rep ex)

if (mouse.IsButtonDown(eMouseLeft) && GuiControl.GetAtScreen(mouse.x, mouse.y) == BtnSkip && IsTimerExpired(1)) { // if button is down and timer has expired
     
PreviousPos += 5000; // add 5 seconds to the mp3 position variable
SeekMP3Millis(PreviousPos); // seek to that position
SetTimer(1,20); //play for 20 game loops

}



This wont work as-is but it gives an idea of how i would do it.

m0ds

Thanks Calin, not bad. It's part working, but for some reason with the "IsTimerExpired" in there it does nothing what so ever. Remove that and it just jolts the track around the same spot, but doesn't move forward through it. So I realise it's needed but no idea. Any thoughts?

Here's the working (ish) code from your help:

Code: ags

if (mouse.IsButtonDown(eMouseLeft) && GUIControl.GetAtScreenXY(mouse.x, mouse.y) == seekfwd && IsTimerExpired(1)) { // if button is down and timer has expired
int PreviousPos;
    //QuitGame(0);
PreviousPos += 5000; // add 5 seconds to the mp3 position variable
SeekMP3PosMillis(PreviousPos); // seek to that position
SetTimer(1,20); //play for 20 game loops

}

Dualnames

I kind of tried a lot not to post, but Mods is that you?
Also, why not use a slider instead? It'll be cooler!





Code: ags

//Place this, I don't know when you need to get the song?
Slider.Max=50000;//song duration (there's the function but look when I'm posting this!!)

function Slider_Change() {
SeekMP3PosMillis(Slider.Value);
}
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

m0ds

#8
A novel idea Jimbo, but it wouldn't work for my purposes as a slider :(

However that does give me a backup way of making the normal button version work...hmmm :)
* Mods goes back to AGS

EDIT. Ah, problem there really is that AGS 2.72 can't read the total milliseconds of an mp3 file....?

NUTHER EDIT: I have a crude version working now, using a slider... :P

Calin Leafshade

The problems with the code are 2 fold

PreviousPos is reinitialised everytime the function starts which resets it to zero.
it needs to be roughly equal to the amount of time the track has been playing.

Also the timer will not have expired because it will have never been set.

So try something like this.

Again, untested and very possibly bollocks.


Code: ags

bool Clicked;

function repeatedly_execute(){
if (mouse.IsButtonDown(eMouseLeft) && !Clicked){
Clicked = true;
SetTimer(1,1); //set the timer when you first click the button so the following code runs.
}
if (!mouse.IsButtonDown(eMouseLeft)) Clicked = false

if (mouse.IsButtonDown(eMouseLeft) && GUIControl.GetAtScreenXY(mouse.x, mouse.y) == seekfwd && IsTimerExpired(1)) { // if button is down and timer has expired
int PreviousPos = GetMP3PosMillis();
PreviousPos += 5000; // add 5 seconds to the mp3 position variable
SeekMP3PosMillis(PreviousPos); // seek to that position
SetTimer(1,20); //play for 20 game loops

}
}


Dualnames

#10
Are you actually going for the slider, Calin's idea, a mix? Or should we just fight over for you, and you pick the coolest?

The question is using this:
Code: ags

SeekMP3PosMillis(30000);


Means the song goes 30000 loops from the start. Question which isn't explained on manual: If I use this function to do this:
Code: ags

SeekMP3PosMillis(1600000);


And the song duration from the start is less than 1.600.000 loops, there's really no chance of knowing is there?

EDIT: At least not till AGS 3.1.2 no

EDIT 2:
AGS  3.2.0 Manual
Quote

LengthMs property
readonly int AudioChannel.LengthMs

Gets the length of the audio playing on this channel, in milliseconds.
This is supported by all file types, but with MIDI music it is only accurate to the nearest second.

If this channel is not currently playing any audio, returns 0.

Example:

AudioChannel *channel = aExplosion.Play();
Display("The Explosion sound is %d ms long.", channel.LengthMs);

will start playing the aExplosion audio clip, then display its length.
Compatibility: Supported by AGS 3.2.0 and later versions.

Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

m0ds

Thanks guys! Sadly I'm a 2.72 dude so that's why I'm looking for more basic solutions. You're right though Jim, unless I was to work out the milliseconds for each song (and there are 30 or so of them) then there is a danger of AGS crashing if I've requested it to play through more milliseconds than exist. But the slider thing helps, and only being able to fast forward through half a song or so is okay.

And cheers Calin, I'll try your update - see how it goes. :)

Dualnames

Quote from: Mods on Tue 27/04/2010 14:28:22
Thanks guys! Sadly I'm a 2.72 dude so that's why I'm looking for more basic solutions. You're right though Jim, unless I was to work out the milliseconds for each song (and there are 30 or so of them) then there is a danger of AGS crashing if I've requested it to play through more milliseconds than exist. But the slider thing helps, and only being able to fast forward through half a song or so is okay.

And cheers Calin, I'll try your update - see how it goes. :)

I know it's hard to update on 3.0, but once you do it, and stick with it, getting to 3.2.0 is literally nothing. I've made the step and I know how un-friendly and unsettling it is. Mods, you can however cheat on AGS the best way you can. You can use a gui, or somehow force the player to click or something.

Code: ags

//Global Variables//
bool getmahmusic=false;
int countmein=0;

function repeatedly_execute_always() {//I'm not sure if repeatedly execute only will work.
if (getmahmusic==true) 
SetMusicRepeat(0);
while (IsChannelPlaying(1)==1) {//You need to find which channel AGS is using to play the mp3 files
countmein++;
}
SetMusicRepeat(1);
getmahmusic=false;
Silder.Max=countmein;
PlayMP3File("chesney.mp3");
countmein=0;
EndCutscene();
}
}

//place this when you need to start the file
PlayMP3File ("chesney.mp3");
getmahmusic=true;
StartCutscene();//whatever you set that command with
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk