隨筆 - 8  文章 - 55  trackbacks - 0
          <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿(6)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          朋友的Blog

          最新評論

          閱讀排行榜

          評論排行榜

          FlashCom發布和播放MP3
          播放MP3文件
          我們知道,Flash中默認的流式播放格式是Flv格式,但是在應用程序中,你可以通過客戶端腳本來播放MP3音頻文件和ID3信息,并使用服務器端腳本發布到stream流。
          你需要上傳MP3文件到服務器端的/streams/application_instance目錄(Macromedia FCS MX 1.5 在錄制視頻流的時候會自動創建 streams 目錄,如果不存在,你也可以手動創建)。例如你有個名為CDPlayerApp應用程序,你可以上傳MP3文件到/applications/CDPlayerApp/streams/application_instance目錄。
          通過設定共享目錄,你還可以在其它應用程序之間共享MP3。
          找到Vhost.xml文件中的節點,在中添加需要共享的目錄,如:
          foo;c:\data
          表示所有含有foo名稱的目錄都會被定向到c:\data目錄,如foo/bar會被定向為c:\data\bar.flv。
          詳細的Vhost.xml說明可以參考FlashCom管理手冊中相關部分。
          然后,通過Stream.play指令指定播放的路徑和想要播放的MP3文件。為了播放MP3文件,我們需要使用 NetStream對象的play方法,或者使用MC對象的attachAudio方法,特別需要注意的是,在播放文件前面要加上mp3播放標識前綴 mp3:,我們來看代碼示例:
          引用:
          1 : //非共享方式播放
          2 : vidObj.attachVideo(mystream);
          3 : mystream.play( 'mp3:bolero' );
          4 : //文件bolero.mp3在FCS服務器的 C:\mp3_files 目錄下面
          5 : //該目錄在vhost.xml中被映射到虛擬目錄 mp3dir
          6 : movieObj.attachAudio(mystream2);
          7 : mystream2.play( 'mp3:mp3dir/bolero' );

          提示: 在使用 NetStream.play 方法的時候如果不指定視頻或音頻格式,會默認為FLV格式, 所以在播放MP3的時候,你必須指定格式播放。也就是說,flv:granada和granada都會播放文件granada.flv,但是mp3:bolero只會播放文件bolero.mp3。注意,這里播放的文件都在服務器端。

          要播放MP3文件的ID3信息,必須使用播放前綴id3:并定義相應的回調函數來捕捉id3數據。例如,顯示bolero.mp3文件的ID3 信息:

          引用:
          1 : //displays the ID3 tag of bolero.mp3
          2 : mystream.play( 'id3:bolero' );
          3 : //callback function to capture the ID3 data. Data will be displayed with
          4 : //'info.' preceding the data from the tag, for example, info.songtitle.
          5 : mystream.onId3 = function (info){
          6 : for (i in info){
          7 : trace(i + ':' + info[ i ]);
          8 : }
          9 : }

          支持的MP3 ID3信息的版本
          FlashCom server 1.5 支持UTF-8, UTF-16, and ISO-8859-1 格式的 1.0, 2.3和 2.4.版本的ID3信息,并且只支持文本數據,例如:歌曲名、作者、備注和錄制時間等。

          使用服務器端腳本
          你還可以使用服務器端的Stream對象來播放MP3和獲取MP3文件的長度,更詳細的可以參考服務器端腳本參考中的Stream.play and Stream.length
          要刪除MP3文件可以使用Application.clearStreams方法,
          下面來看一個例子,通過Stream.play方法來發布MP3:
          引用:
          01 : // Set up the server stream
          02 : application.myStream = Stream.get( 'music' );
          03 : if (application.myStream)
          04 : {
          05 : // Publish the MP3 file bolero.mp3 to the stream 'music'
          06 : // Use the mp3: prefix in front of the stream name and specify 0 for the
          07 : startTime parameter to indicate the server should play the recorded stream
          08 : bolero.mp3
          09 : application.myStream.play('mp3:bolero', 0, -1);
          10 : }

          使用 Stream.play 方法來捕獲和播放 ID3 信息,請參考下面的代碼示例:
          引用:
          01 : // Set up the server stream
          02 : application.myStream = Stream.get( 'description' );
          03 : application.myStream.onId3 = function(info)
          04 : {
          05 : for (i in info)
          06 : {
          07 : trace(i + ': ' + info[ i ]);
          08 : }
          09 : }
          10 : if (application.myStream)
          11 : {
          12 : // Publish the ID3 text tag data of bolero.mp3 to a stream 'description'.
          13 : // Use the id3: prefix in front of the stream name and specify 0 for the
          14 : startTime parameter
          15 : application.myStream.play( 'id3:bolero', 0, -1);
          16 : }
          posted on 2006-06-16 11:25 blog搬家了--[www.ialway.com/blog] 閱讀(362) 評論(0)  編輯  收藏 所屬分類: FMS
          主站蜘蛛池模板: 湖口县| 兰溪市| 三门县| 蓝田县| 溆浦县| 宁陵县| 石景山区| 宜君县| 库伦旗| 上饶县| 延寿县| 宁武县| 班玛县| 澎湖县| 神农架林区| 容城县| 嘉定区| 鹿泉市| 广州市| 仁化县| 五河县| 芮城县| 宣恩县| 娄烦县| 井研县| 大名县| 唐河县| 和田县| 泗阳县| 沐川县| 永平县| 原平市| 牡丹江市| 垫江县| 罗城| 二手房| 洪泽县| 池州市| 怀宁县| 河曲县| 康平县|