I created custom class that play's mp3 form uax file (galaxy can handle mp3's imported directly to uax as well). But I have problem with disabling music. When music is not loaded in to the level, everything works fine (sound plays properly), but when I load music (in LevelProperties) and then plays mp3 with my trigger (with var bDisableMusic turned on), sound plays for 2 seconds and instantly mute. I though that this problem comes from ClientPlaySound, So I write a new one:
but this doesn’t change nothing. So now I don't know why this code don't work as I want it to. Anyone can help me with this? Here is Trigger code:
Code:
simulated function RPGPlaySound(sound ASound, optional ESoundSlot Slot, optional bool bInterrupt, optional bool bVolumeControl )
{
local actor SoundPlayer;
LastPlaySound = Level.TimeSeconds; // so voice messages won't overlap
SoundPlayer = self;
SoundPlayer.PlaySound(ASound, Slot, 16.0, bInterrupt);
}
Code:
class TCOMusicPlayer extends TCOTriggers;
//#exec TEXTURE IMPORT NAME=empeT FILE="textures\Icons\mp3t.bmp" GROUP=Icons LODSET=2
#exec TEXTURE IMPORT NAME=empeP FILE="textures\Icons\mp3p.bmp" GROUP=Icons LODSET=2
#exec OBJ LOAD FILE="..\Music\NoMusic.umx" PACKAGE=NoMusic
var(Mp3Player) sound MPThree; //mp3
var(Mp3Player) bool bLoopMusic; //loop mp3?
var(Mp3Player) bool bAffectAllPlayers;
var(Mp3Player) bool bDisableMusic; //disable music
var(Mp3Player) music SilentSong;
var MaleFour PlayerInstigator;
//play control stuff
var float SoundLength;
var float DebugSL; // for debug
var bool bPlaying;
function PostBeginPlay()
{
disable('Tick');
}
function Trigger( actor Other, pawn EventInstigator )
{
if(MPThree != none)
{
PlayerInstigator=MaleFour(EventInstigator);
PlayMPThree();
enable('Tick');
}
}
function GetSoundLength()
{
SoundLength=GetSoundDuration(MPThree);
DebugSL=GetSoundDuration(MPThree); //for debug
}
function CheckForMusic()
{
local pawn P;
if(bAffectAllPlayers)
{
for (P=Level.PawnList; P!=None; P=P.NextPawn)
if (P.bIsPlayer && P.IsA('PlayerPawn'))
{
PlayerPawn(P).ClientSetMusic(SilentSong, 0, 255, MTRAN_Fade);
}
}
else
{
PlayerInstigator.ClientSetMusic(SilentSong, 0, 255, MTRAN_Fade);
}
}
function PlayMPThree()
{
local pawn P;
GetSoundLength();
bPlaying=true;
if(bAffectAllPlayers)
{
for ( P=Level.PawnList; P!=None; P=P.NextPawn )
if ( P.bIsPlayer && P.IsA('MaleFour') )
MaleFour(P).RPGPlaySound(MPThree, SLOT_Interface, true);
}
else
{
PlayerInstigator.RPGPlaySound(MPThree, SLOT_Interface, true);
// BroadCastMessage("mp3="$MPThree);
}
if(bDisableMusic)
{
CheckForMusic();
}
// BroadCastMessage("Test!!! Played: "$SoundLength$" from: "$DebugSL); //debug
}
function Tick(float DeltaTime)
{
if (bPlaying)
{
SoundLength -= DeltaTime;
// BroadCastMessage("Tick works! Played: "$SoundLength$" from: "$DebugSL); //another debug :)
if (SoundLength <= 0)
{
if(bLoopMusic)
PlayMPThree();
else if(!bLoopMusic)
{
bPlaying=false;
disable('Tick');
}
}
}
}
defaultproperties
{
DrawType=DT_Sprite
bHidden=true
Texture=Texture'CHSystem.Icons.empeP'
bLoopMusic=true
bPlaying=false
bAffectAllPlayers=false
bDisableMusic=true
SilentSong=music'NoMusic.null'
}