2

I'm developing a web app with PHP and I need to test if a page of a website has background music. As many of you already know, this is the list of the tag (I miss someone?) where the background sound can be inserted in a webpage:

  1. Embed
  2. Object
  3. Bgsound
  4. Audio (HTML5)

While checking if there's background audio because of the presence of the tag bgsound or audio is easy to do, testing if a flash animation has the sound is not so easy (at least for me). I know that I can check if a tag embed has in the src attribute something like sound.mp3 but how can I test if the sound is totally embedded in the flash animation?

I searched a lot to find an answer but unfortunately I've not found one.

Thanks to everyone who will answer to my question.

3
  • If you just want to see if a Flash file contains sound, then you can download the file and parse it to see if there are any sounds in there - but there could still be music even if there isn't; it might download it from an external file. Oct 26, 2011 at 0:16
  • @MichaelMadsen Your comment is really interesting. Can you please improve it? How can I parse that file using PHP and what I have to search? Oct 26, 2011 at 0:18
  • It became too long for a comment, so I fleshed the process out to an answer. Also note that not all SWFs are embedded directly from HTML; these days the HTML usually gets generated using JavaScript, so you wouldn't see any <object> tags in the HTML you download - that's also something you'll need to be aware of. Oct 26, 2011 at 0:48

1 Answer 1

2

An SWF file consists of a number of different tags, each of which describes a different type of content; bitmapped images, ActionScript, shapes, fonts, and indeed sounds. We can therefore download the SWF file, read the tags, and see if there are any sound-related tags in there (for music, you'd be looking specifically for tags related to streaming sound).

To do that, you would use some SWF parsing library (I don't know of any for PHP, but I'm sure they exist), or you could implement your own based on the specification.

However, this can only detect cases where the sound is actually embedded, which may not be the case at all - the sound can get streamed from an external file, and handled entirely in ActionScript (and indeed, this is not all that uncommon).

To handle that case, the ActionScript code can be disassembled, and the instructions can then be checked to see if they reference any audio-specific ActionScript classes (I don't know the bytecode well enough to know how you would check that; I just know it can be done). If so, then you know that the SWF has some connection to audio (but it doesn't have to be actual background music).

Of course, if you want a foolproof solution you also have to consider that an SWF can load other SWFs - the SWF file that does the playing may not be the one you downloaded, so you would need to somehow find these SWF files and download those as well, then run them through the same process...

As you can see, this can quickly become very, very complicated, and therefore it's effectively impossible to ensure 100% accuracy. You will have to determine for yourself how accurate your detection needs to be (and by extension, how much effort you would be willing to expend on it).

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.