tags:

views:

526

answers:

5

Is there a way to detect if a flash movie contains any sound or is playing any music?
It would be nice if this could be done inside a webbrowser (actionscript from another flash object, javascript,..) and could be done before the flash movie starts playing.

However, I have my doubts this will be possible altogether, so any other (programmable) solution is also appreciated

+3  A: 

Yes, on the server side for sure. Client side? I don't know. (I'm a serverside kind of guy.)

On the server side, one would have to parse the file, read the header and/or look for audio frames. (I've ported a haskel FLV parser to Java for indexing purposes myself, and there are other parsing utilities out there. It is possible.)

osflash.org's FLV page has the gory details. Check out the FLV Format sections's FLV Header table.

FIELD       DATA TYPE      EXAMPLE                  DESCRIPTION
 Signature   byte[3]        “FLV”                    Always “FLV”
 Version     uint8          “\x01” (1)               Currently 1 for known FLV files
 Flags       uint8 bitmask  “\x05” (5, audio+video)  Bitmask: 4 is audio, 1 is video
 Offset      uint32-be      “\x00\x00\x00\x09” (9)   Total size of header (always 9 for known FLV files)


EDIT: My client side coding with Flash is non-existent, but I believe there is an onMetaDataLoad event that your code could catch. That might be happening a bit late for you, but maybe it is good enough?

Stu Thompson
A: 

Stu, that's already a really nice answer!
With a few modifications, that solution might even be possible for me. Still, if anyone knows a way to do this client-side, then your suggestions are more than welcome

Sven
+1  A: 

Are you asking about FLV video files or Flash "movies" as in SWF?

Just to clarify, an FLV is the Flash Video Format (or whatever the acronym is), a regular Flash movie/application/banner would be an SWF. These are very different file formats.

grapefrukt
A: 

grapefrukt, as a response to your question, I'm talking about swf files mainly, but flv files are also a valid alternative if no other options are available.

Sven
A: 

With the ByteArray you can do pretty much what you want. Before starting playback you can analyze the bytes of the FLV header (use byteArray.readByte() and refer to the specs) to determine to check if the audio flag is on. Since the FLV header is loaded almost instantly this shouldn't cause any inconvenient delay for the user.

With SWF's it's a lot tricker -- i'm pretty sure there's no easy way to determine in advance if a swf plays audio somewhere. A way to do it could be to look at what assets the SWF has defined in the library but also then the swf could just load an external audio file (or even generate it with some hacks or the new apis in Flash player 10). If the swf's are user submitted (or something similar that's out of your immediate control) I think this is a risky road..

Antti