3

Our Flash web-based applications play lots of audio for narration and sound-effects. Some of our customers have firewall rules that block downloading of MP3 and other audio files. So, we need to wrap those MP3 files in SWFs. In the past, I've written JSFL scripts that automate the Flash IDE and walk through a complicated, fragile set of steps to embed MP3 files into FLAs and then publish those to SWFs. Now, Flex SDK provides the mxmlc compiler. I've mixed ANT into our workflow, and command-line and automated builds have been a joy. So, I want to make transcoding or wrapping of MP3s part of our build process. I've found Embedding Asset at Compile time in Pure AS3, but this will require that I write a script to generate a wrapper class AS file. Is there a cleaner way to wrap or transcode MP3 files into SWFs? I suppose I'm hoping there is a method for passing the mp3 directly to mxmlc and outputting a swf, but any recommendation better than generating actionscript wrapper classes would be greatly appreciated.

4

1 に答える 1

2

既に MXMLC と Ant を使用しているため、Ant ビルド スクリプトに別のコードを追加して、MP3 をライブラリ SWC にビルドすることを検討する必要があります。その後、その SWC を実行可能な SWF にビルドできます (以下の例では、その簡単な手順を省略しています)。

必要なのは Ant だけなので、この方法で行うのは、既に SWF を構築している方法と同じです。唯一の本当の「落とし穴」は、MXMLC/SWC に適した絶対パス(「/myAssets/myasset.mp3」など) を使用してファイルをコードに埋め込む必要があることです。

プロジェクトのメタデータにアクセスできるため、Flash Builder はプロジェクトのルートがどこにあるかを「認識」し、相対埋め込みパスを使用できるようにします。MXMLC には、この情報はありません。したがって、SWC でのファイルの保存方法の絶対位置と一致するように埋め込みが宣言されていることを確認する必要があります。これを行うと、Flash Builder と MXMLC/Ant の両方が埋め込みを理解できるようになります。そうすれば、みんな幸せです。

参考までに、アセット SWC を構築するための Ant スクリプトの例を以下に示します。簡単に言えば、主な手順は次のとおりです。

  • 含めるファイルの場所を含む文字列を 1 つずつ作成します
  • MXMLC とモンスターサイズのコマンドライン引数セットを使用して、これらのアセットを SWC にコンパイルします。

次のスクリプトは、jpg、png、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>

私たちはこのアプローチ (インターネットで見つけた断片をつなぎ合わせたものです。場所を覚えていれば、喜んで信用を差し上げたいと思います) を使用して、大規模なモジュールベースのプロジェクトと、それに埋め込まれた画像とフォントを構築します。オーディオファイルでは機能しないと考える理由はありません。

幸運を、

テイラー

PSそこに残っている/役に立たないコード行がいくつかあるかもしれません。また、私は Ant の専門家ではないので、"Ant の連中" の皆様へ: 私がベスト プラクティスを破った場合は、ご容赦ください ;)

于 2011-04-05T22:39:31.027 に答える