使用过flash做音乐播放器的朋友应该知道..
flash只支持mp3格式的音乐文件
PS:
1.当然还有flv和mp4相关的声音格式..今天就不多讨论了..
2.这里说的是纯AS环境..调用JS就不多说了...
不过上周noteflight在google code发布StandingWave(http://code.google.com/p/standingwave/)
该类库可以让AS3播放wav..由于网上的介绍比较少..今天顺便介绍一下使用方法
调用步骤很简单~~
1.首先以ByteArray另载wav文件..
2.使用以下代码即可进行最基本播放..
new AudioPlayer().play(WaveFile.createSample(data));//其中data为wav文件的byte对象;
下面的例子在运行swf后会打开系统的文件浏览框..选择wav文件即运行播放..
01.
package
{
02.
import
com.noteflight.standingwave2.formats.WaveFile;
03.
import
com.noteflight.standingwave2.output.AudioPlayer;
04.
import
flash.display.Sprite;
05.
import
flash.events.Event;
06.
import
flash.net.FileFilter;
07.
import
flash.net.FileReference;
08.
public
class
StandingWave2HelloWorld
extends
Sprite
09.
{
10.
private
var
file:FileReference;
11.
private
var
player:AudioPlayer;
12.
public
function
StandingWave2HelloWorld()
13.
{
14.
file =
new
FileReference();
15.
file.addEventListener(Event.SELECT,select);
16.
file.addEventListener(Event.COMPLETE,complete);
17.
file.browse([
new
FileFilter(
"wav文件"
,
"*.wav"
)]);
18.
}
19.
private
function
select(e:Event):
void
20.
{
21.
file.load();
22.
}
23.
private
function
complete(e:Event):
void
24.
{
25.
player =
new
AudioPlayer();
26.
player.play(WaveFile.createSample(file.data));
27.
}
28.
}
29.
}
而这个例子则结合了一些开始~停止~事件~进度的简单应用..
请点击右方按钮打开文件...
(ps:界面来自"QQ影音",另外由于只是展示StandingWave2的使用,UI逻辑比较随便..像播放完后没有重置播放按钮等..);
注意:此类只能对未进行压缩的wav进行播放...所以不是所有wav都能用..下面提供一个测试wav.. WAV文件 (2.6 MiB, 83 hits)
相关文件 (45.0 KiB, 51 hits)