Is it possible to use mp3s as a continuous background track in scratch?
Offline
Hi welshrearbit,
you can import mp3s as sounds in to Scratch, and then play them in a continous loop like this:
[blocks]
<when green flag clicked>
<forever>
<play sound[ mp3 ]and wait>
<end>[/blocks]
It will automatically be 'background' music, because in Scratch you can have your project do several things simultaneously, using 'event hats'.
For example you can have an additional script (even in the same sprite) that also starts when the green flag is pressed, something like this:
[blocks]
<when green flag clicked>
<forever>
make the sprite or the stage do something else
<end>[/blocks]
Since both of these scripts will run in parallel, your mp3 music-loop will behave just like background music.
Hope that helps....
P.S. I moved this post to ehe "All About Scratch" forum section
Offline
Offline
Jens wrote:
Hi welshrearbit,
you can import mp3s as sounds in to Scratch, and then play them in a continous loop like this:
[blocks]
<when green flag clicked>
<forever>
<play sound[ mp3 ]and wait>
<end>[/blocks]
It will automatically be 'background' music, because in Scratch you can have your project do several things simultaneously, using 'event hats'.
For example you can have an additional script (even in the same sprite) that also starts when the green flag is pressed, something like this:
[blocks]
<when green flag clicked>
<forever>
make the sprite or the stage do something else
<end>[/blocks]
Since both of these scripts will run in parallel, your mp3 music-loop will behave just like background music.
Hope that helps....
P.S. I moved this post to the "All About Scratch" forum section
i did not c your post,so i made the other post.
Offline
two sprites: "on" and "off"
when on clicked
forever
play sound <> and wait
when off clicked
stop all sounds
Offline
um... when i tried importing the mp3, it said "unrecognized audio file format". HELP
Offline
It is possible that the mp3 file is not encoded in the standard MPEG-3 format. Try using Audacity (free download) to convert your file to a real mp3 file perhaps?
Offline
kevin_karplus wrote:
two sprites: "on" and "off"
when on clicked
forever
play sound <> and wait
when off clicked
stop all sounds
the problem with this is that once the music would have normally finished it plays again
Offline
Ah, now I think I understand. Why don't you try using a flag variable:
one single sprite "music"
"music" variable: "on"
[blocks]
<when green flag clicked>
<set{ on }to( 1
<forever if><( <{ on }> <=> 1 )>
<play sound[ mp3 ]and wait>
<end>
<when[ music ]clicked>
<if><( <{ on }> <=> 1 )>
<set{ on }to( 0
<stop all sounds>
<else>
<set{ on }to( 1
<end>
[/blocks]
(What am I doing wrong here, these forum blocks look awful, maybe I should revert to text mode, like Kevin...)
Offline
I've found the blocks mode on the website to be pretty useless---the blocks are not carefully enough done to fit together well and look right, so it is probably clearer to type text.
Thanks, Jens, for correcting my suggestion. Draakx was right in pointing out that what I had first proposed would keep on restarting the music.
Perhaps I'm unusual, but I find repeat loops of music extremely irritating, so I never put them in any of my projects.
Offline
mijet97 wrote:
um... when i tried importing the mp3, it said "unrecognized audio file format". HELP
Same problem here, Scratch ver. 1.2.1. And even a major crash trying various mp3. From Audacity and Magix Music Maker 14
from dumpfile....
---------------------------------------
Exception code: C0000005
Exception addr: 67E04016
Access violation (read access) at 00000014
EAX:00000000 EBX:00000000 ECX:00000001 EDX:00000000
ESI:108DC5B8 EDI:101617C0 EBP:67E01378 ESP:0006FB84
EIP:67E04016 EFL:00010202
FP Control: FFFF027F
FP Status: FFFF0120
FP Tag: FFFFFFFF
VM Version: Squeak 3.4.3 / Tea 1.9 VM (release) from Apr 8 2003
Compiler: gcc 2.95.2 19991024 (release)
Current byte code: 243
Primitive index: 117
Loaded plugins:
Mpeg3Plugin 27 October 2000 (e)
------------------------------------------------------------------------------
Plugin old? Or what...
//Anders
Offline
Jens wrote:
Ah, now I think I understand. Why don't you try using a flag variable:
one single sprite "music"
"music" variable: "on"
[blocks]
<when green flag clicked>
<set{ on }to( 1
<forever if><( <{ on }> <=> 1 )>
<play sound[ mp3 ]and wait>
<end>
<when[ music ]clicked>
<if><( <{ on }> <=> 1 )>
<set{ on }to( 0
<stop all sounds>
<else>
<set{ on }to( 1
<end>
[/blocks]
(What am I doing wrong here, these forum blocks look awful, maybe I should revert to text mode, like Kevin...)
The exact same script I had in my Weather Simulator project! ^_^
Offline
Hi, SmeAnd.
It sounds like your MP3 files are either corrupted or in a format that Scratch cannot read. The MP3 code is based on some open-source code that is not entirely robust in the face of MP3 file formats that it doesn't like.
Your sound software may be creating mp4 formatted files rather than true mp3 files. You may be able to do a "save as" or set the preferences to export the sounds in a format that Scratch can read. If you can save or convert your files as uncompressed WAV files, Scratch should be able to import them. (Note: There are no space savings for importing MP3 files as opposed to WAV files. The sound gets stored internally in the same format no matter what the original sound file format was.)
Good luck!
-- John
Last edited by johnm (2008-01-02 10:51:52)
Offline