Wrap or embed and MP3 in SWF using the Flex mxmlc compiler

Our Flash-based Flash applications play a variety of audio material for storytelling and sound effects. Some of our customers have firewall rules that block the downloading of MP3s and other audio files. So, we need to wrap these MP3 files in SWF. I used to write JSFL scripts that automated the Flash IDE and went through a complex, fragile set of steps for inserting MP3 files into FLA and then publishing them to SWF. The Flex SDK now provides the mxmlc compiler. I mixed ANT in our workflow, and the command line and automatic builds were fun. So, I want to make transcoding or wrapping MP3 files part of our build process. I found Embedding Asset during compilation in Pure AS3but this will require that I write a script to create an AS wrapper class file. Is there a cleaner way to wrap or transcode MP3 files to SWF? I suppose I hope that there is a method for transferring mp3 directly to mxmlc and swf output, but any recommendation is better than creating actioncript wrapper classes would be greatly appreciated.

+3
source share
1 answer

Since you are already using MXMLC and Ant, you should consider adding another bit of code to the Ant build script to create your MP3 files in the SWC library. You can then create this SWC into an executable SWF (I left this simple step from my example below).

, , Ant, , SWF. "gotcha" , MXMLC/SWC (, "/myAssets/myasset.mp3" ) .

, Flash Builder "", , . MXMLC . , , SWC. , Flash Builder MXMLC/ Ant . , .

, Ant script SWC. , :

  • , , ,
  • SWC, MXMLC

script jpgs, pngs, svgs, ttfs, xml , MP3 "assets.swc". flexTasks.jar( ) ant -contrib.jar FLEX_HOME.

<?xml version="1.0" encoding="utf-8"?>
<project name="My App Builder"
    basedir="."
    default="buildSWC"
    xmlns:antcontrib="antlib:net.sf.antcontrib">
  <taskdef resource="flexTasks.tasks" classpath="${basedir}/libs/flexTasks.jar"/>
  <taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${basedir}/libs/ant-contrib-1.0b3.jar"/>

  <property environment="env"/>

  <property name="FLEX_HOME" value="${env.FLEX_HOME}"/>
  <property name="ASSETS_FILE" value="assets.swc"/>
  <property name="SRC_DIR" value="./src"/>

  <!-- Prepare folders for SWC compilation -->
  <target name="buildSWC">
    <echo message=""/>
    <echo message="*****************************************************"/>
    <echo message="* ${ASSETS_FILE}"/>
    <echo message="*****************************************************"/>
    <echo message="...basedir: ${basedir}"/>

    <!-- Build a swc from statically-included assets (images, mp3s, xml files, properties files) -->
    <fileset id="assets.flex" dir="src" includes="**/*.jpg,**/*.png,**/*.mp3,**/*.css,**/*.svg,**/*.swf,**/*.TTF,**/*.jpeg,**/*.xml,**/*.properties"/>
    <pathconvert pathsep=" " property="assets.flex.output" refid="assets.flex" dirsep="/">
      <map from="${basedir}/src/" to=""/>
    </pathconvert>

    <echo message="...Resources being considered..."/>
    <var name="filelist" value=""/>
    <var name="prefixfilelist" value="-include-file"/>
    <for list="${assets.flex.output}" delimiter=" " param="asset">
      <sequential>
        <echo>Asset: @{asset}</echo>
        <propertyregex property="prop"
                       input="${asset}"
                       regexp="(.*)${SRC_DIR}/(.*)"
                       select="\2"
                       casesensitive="false"
                       defaultvalue="./src/"/>
        <echo>Prop: ${prop}</echo>
        <var name="filelist_tmp" value="${filelist}"/>
        <var name="filelist" unset="true"/>
        <var name="filelist"
             value="${filelist_tmp} ${prefixfilelist} ./@{asset} ${prop}@{asset}"/>
        <var name="prop" unset="true"/>
      </sequential>
    </for>
    <echo message="-output ${ASSETS_FILE} ${filelist}"/>

    <!-- Windows Compile -->
    <exec executable="${FLEX_HOME}/bin/compc.exe"
          failonerror="true"
          osfamily="winnt">
      <arg line="-output ./libs/assets.swc ${filelist}"/>
    </exec>

    <!-- Unix/Linux Compile -->
    <exec executable="${FLEX_HOME}/bin/compc"
          failonerror="true"
          osfamily="unix">
      <arg line="-output ./libs/assets.swc ${filelist}"/>
    </exec>
  </target>
</project>

( , - , , ) , . , .

,

P.S. / . , Ant, "Ant " : , ;)

+2

Source: https://habr.com/ru/post/1745260/


All Articles