Looping an MP3
by BeyondtheTech · in iTorque 2D · 05/22/2009 (8:14 am) · 6 replies
I've read the other threads where it's easy as two lines when wanting to play an MP3 file in the background.
However, I wanted to loop the MP3 continuously until I decide to change up the music.
I tried going back to this code, but I'm not getting any music... am I missing something? Is there a simple one-liner like the top version, or additional parameter needed that will loop the MP3?
$musicStreamFile = "~/data/audio/slowtempo.mp3"; $musicStreamHandle = startiPhoneAudioStream($musicStreamFile,500);
However, I wanted to loop the MP3 continuously until I decide to change up the music.
// background music
new AudioDescription(BGM)
{
volume = 1.0;
isLooping = true;
is3D = false;
type = $GuiAudioType;
};
...
function getAudio(%name, %type)
{
if (isObject(%name))
return;
new AudioProfile(%name)
{
filename = "~/data/audio/" @ %name @ ".mp3";
description = %type;
preload = false;
};
}
...
function playBGM(%sound, %volume)
{
// get profile for background music and set default volume
getAudio(%sound, "BGM");
alxSetChannelVolume($GuiAudioType, %volume);
// if another bgm is playin, turn it off
if ($bgm)
$bgm = alxStopAll();
// play bgm
$bgm = alxPlay(%sound);
}
...
playBGM("fasttempo", 1.0);I tried going back to this code, but I'm not getting any music... am I missing something? Is there a simple one-liner like the top version, or additional parameter needed that will loop the MP3?
#2
05/22/2009 (11:15 am)
Well, that was simple enough. Thanks!
#3
I´ve tried:
but doesn´t works... is there such method???
Thanks
Mike
07/09/2009 (3:04 pm)
and how to stop a music file???I´ve tried:
stopiPhoneAudioStream($musicStreamFile);
but doesn´t works... is there such method???
Thanks
Mike
#4
07/09/2009 (3:08 pm)
It seems I´ve made a wrong calling, I should use:stopiPhoneAudioStream($musicStreamHandle);
#5
Thanks
07/25/2009 (1:04 pm)
This works great, but does anyone know how to put a fade on the iPhoneAudioStream? Or to point me to where this would be in the documentation?Thanks
#6
07/25/2009 (1:40 pm)
I fear you can't unless you don't care about performance and move the mp3 to software decoding.
Torque 3D Owner Mat Valadez
Default Studio Name
Should be this:
Streaming mp3 is specific to the iPhone and doesn't go through iTGB normal audio profile stuff, alxPlay, alxStop, etc. won't do anything.