[转]flex中嵌入mp3声音文件

[url]http://www.it118.org/specials/be5aa227-758a-4292-a143-5d0de10556fb/e63a3d74-0078-4c71-b348-33522564d843.htm[/url]


您可以在 Flex 应用程序中通过使用 [Embed] 元数据标签嵌入 MP3 文件并播放它。

注意: 记住嵌入的声音文件会成为您的应用程序 (最终的 SWF 文件) 的一部分, 而 MP3 文件会很大, 从而会使您的应用程序变得很大并会对应用程序的下载速度产生负面影响。

此实例将该 MP3 的一个新实例创建为一个 SoundAsset。它使用 SoundAsset 类的 play() 方法来播放 MP3 文件的实例, 并存储返回的 SoundChannel 对象, 从而您可以稍后调用 SoundChannel 对象的 stop() 方法以结束播放。


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" horizontalAlign="center" verticalAlign="center" viewSourceURL="srcEmbeddingSoundFiles/index.html">

<mx:Script>
<![CDATA[
import mx.core.SoundAsset;
import flash.media.*;

[Embed(source="assets/pie-yan-knee.mp3")]

[Bindable]
public var Song:Class;

public var mySong:SoundAsset = new Song() as SoundAsset;
public var channel:SoundChannel;

public function playSound():void
{

// Make sure we don't get multiple songs playing at the same time
stopSound();

// Play the song on the channel
channel = mySong.play();
}

public function stopSound():void
{

// Stop the channel, but only if it exists
if ( channel != null ) channel.stop();
}

]]>
</mx:Script>

<mx:HBox>
<mx:Button label="play" click="playSound();"/>

<mx:Button label="stop" click="stopSound();"/>
</mx:HBox>

<mx:Text width="348" textAlign="center" color="#ffffff">

<mx:htmlText>
<![CDATA[<a href="http://derekaudette.ottawaarts.com/music.php">Pie-Yan-Knee Written and Performed by: Derek R. Audette (c) 2004 (Creative Commons Attribution License)</a>]]>
</mx:htmlText>
</mx:Text>

</mx:Application>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值