For a fully working library, supporting Embed, Streams and Radios, please visit HERE!
Somewhere around 2 months ago I was poking around Alchemy’s Ogg Vorbis library. It was a really difficult voyage, trying to understand the barely documented code with little hopes of some proper debugging, because the whole code is put as an SWC file and you can’t access its intestines.
Nevertheless, after around 15 hours of fiddling with it, I managed to get a fully functional, short code for Flex Builder, along with some instructions. Before I start, though, please keep in mind that most of the code was originally written by Adobe staff. What I did was to put it neatly to let more average developers to use it.
Flex Builder 3: In order to make it work, you need to follow a couple of simple steps:
- Grab Flex SDK 3.2 (or later) from Adobe Site. Download Adobe Flex SDK, not the others.
- Unpack the ZIP to folder sdks in your FB3 installation directory.
- In Flex Builder, go to Window->Preferences->Flex->Installed Flex SDKs, click on Add, provide the name (eg. “Flex 3.2″) and path to its directory.
- Grab yourself the OGG Vorbis library from Adobe Alchemy Page.
- Unpack the SWC file wherever you want.
- Create a new ActionScript project, use the 3.2 SDK.
- Go to project properties. Under ActionScript Compiler set the require flash player version to 10.0.0.
- Under ActionScript Build Path->Library Path click on Add SWC. Provide the path to the library. Then set Link Type to Merged into code.
Now copy and paste the code from here, replace the “C:/Test.ogg” to location of some OGG file and test the project.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.






April 8, 2009 at 2:02 pm:
Hi, thanks for this post. I am new to flash so excuse my questions if they seem silly
1) I understand that “C:/Test.ogg” is embedded but fail to see where the file is actually read into the bytearray
2) Is the entire file read into memory for processing. I ask this I want to access an internet radio stream. Would I be able to use the same code?
Thanks
dre
April 8, 2009 at 3:46 pm:
Hi,
@1)This happens on line no. 30:
_audio_bytearray=(new MUSIC_DATA) as ByteArrayThe ogg file you import on line 12 is stored as is in the SWF (so it is identical on the byte level). Then on that line above (eg. 30th) the OGG file is loaded into the _audio_bytearray AS ByteArray.
@2)In this method yes, the whole file is stored in SWF. Originally the code (the Adobe’s) only supported files streamed from server, so it can be used to do that, but streaming Radio is completely different matter, I am not really sure how it works. I was planning to write a complete library supporting both embedded and streamed files. I will poke around it tonight and I can also see if I can get the radio streaming working.
Nevertheless, if you want to try your own strength, I suggest you visit Adobe Alchemy, grab the Ogg Vorbis library with source and see the original code for yourself.
Good luck anyway!
Regards
-Maurycy Zarzycki
April 8, 2009 at 7:38 pm:
Hi M
Got it working using a sample from the actual source code. It now plays external Oggs files but still no streaming. If you look at OggVorbisDecoder it reads the entire file for decoding.
For streaming I would need a different approach – probably reading the stream header, getting chunks at a time for decoding. So in essence a OggVorbisStreamDecoder is required.
dre
April 27, 2009 at 10:35 pm:
Wondering if anyone figured this out yet? I can successfully stream from an internet radio server locally, but from the web it stops loading at 5kb. I am using URLRequest, I think it needs to be done with URLStream or NetStream but haven’t been able to get it working yet.
- Keith
April 27, 2009 at 10:48 pm:
@Keith:
Could you by any chance throw the code you are using on Pastebin, and give me the link? I might be able to come up with something (slim chances though!)
I’ll probably have to investigate a little bit on how internet radios actually work though.
EDIT: I think I might know how to overcome this problem, at least I hope.
Keep Going,
-Maurycy
May 5, 2009 at 1:40 pm:
Hi, as i am making a radio player i am really interested in this. @Maurice “I think I might know how to overcome this problem, at least I hope.” So how is the hope doing? I tried both demos: the Adobe 1 and yours. But i get a Bad Audio Type with adobe while trying to stream radio, getting a normal ogg file works.
@Keith: I would be very interested in trying your code.
Greets,
Kudzo
May 5, 2009 at 2:14 pm:
@Kudzo – Yes, I did manage to write a Frontend for this library, you can grab it from my Latest Post. It should be working fine, because some of the restrictions (for example amount of Hz) are ignored yet everything works as expected.
Keep Going,
-Maurycy
July 17, 2009 at 6:23 pm:
Thanks for sharing the package, i’m having trouble using your frontend package.
Could you provide a sample flex project file?
BTW I’m gettin :
“1046:Type was not found or was not a compile-time constant: SampleDataEvent. OggVorbis Player/src/com/mauft/OggLibrary OggDecoder.as line 47, line 61 ”
and same error on line 95 in OggStream.as
This is with Flex 3.2
July 17, 2009 at 6:53 pm:
Sorry my mistake , i didn’t set the target version for flash to be 10, now it work fine. You can delete my posts.
July 31, 2009 at 6:19 pm:
The code works great for me.
My question is this, on line 45 you have:
_audio_clip.play()
I’m changing is to:
_audio_clip.play(0, 100);
I’m trying to loop it 100 times. The looping works when I use an mp3 file, but for some reason with your code above, no matter how many times I have it loop, it only plays one time.
Any idea why?
-Nick
July 31, 2009 at 6:33 pm:
@Nick – It won’t work, because, I believe, of the way the OGG files are handled. If you want to use looping, I suggest you to download the Ogg Library Fronend I wrote – http://mauft.com/2009/651/alchemy-ogg-vorbis-frontend
September 21, 2009 at 10:37 pm:
Anyone else have bad memory leak with this?
When I profile it in Flex Builder, cmodule.oggvorbis.FlaccYield and cmodule.oggvorbis.CRunner just make endless instances of themselves. Eats up all the memory until the flash player dies.
October 20, 2009 at 1:57 am:
Hi,
Thanks for the code and it works great. I was wondering if its possible to implement see() functionality in the OggStream frontend code? I would appreciate if you could provide a solution.
-Vivek
October 20, 2009 at 1:59 am:
correction I ment seek() functionality
October 20, 2009 at 6:27 am:
No, as far as I know. Maybe they have updated the Ogg Library, but while I was still working on it, Seek(), getLength() and getPostion() all didn’t work.
October 20, 2009 at 3:40 pm:
That was quick. Thank you.
November 9, 2009 at 4:21 pm:
Thanks a lot dude. That’s really awesome ;-)