【发布时间】:2010-09-07 14:25:24
【问题描述】:
我正在尝试构建一个流媒体 .mp3 播放器来在我的网站上运行各种声音文件。为此,我遵循了包含代码模板的教程:
但是,无论我将模板的方向保留到作者自己的声音文件中,还是将我自己的方向插入到我的在线声音文件中,我都会在 ActionScript 中遇到我无法理解的故障。
这些错误是:
1084:语法错误:在 _ 之前需要右括号。
1086: 语法错误:在右括号之前需要分号。
当我尝试纠正它们时,我得到了新的错误。我无法确定声音文件是否正在加载;它当然永远不会播放。音量滑块不起作用。
我确实找到了一条看起来应该被注释掉的行,那一行是
从同一个地方开始
所以我尝试将其注释掉。没有骰子。同样的错误。
提前感谢您的任何建议。代码如下:
var musicPiece:Sound = new Sound(new URLRequest _
("http://blog.0tutor.com/JeffWofford_Trouble.mp3"));
var mySoundChannel:SoundChannel;
var isPlaying:Boolean = false;
to start at the same place
var pos:Number = 0;
play_btn.addEventListener(MouseEvent.CLICK, play_);
function play_(event:Event):void {
if (!isPlaying) {
mySoundChannel = musicPiece.play(pos);
isPlaying = true;
}
}
pause_btn.addEventListener(MouseEvent.CLICK, pause_);
function pause_(event:Event):void {
if (isPlaying) {
pos = mySoundChannel.position;
mySoundChannel.stop();
isPlaying = false;
}
}
stop_btn.addEventListener(MouseEvent.CLICK, stop_);
function stop_(event:Event):void {
if (mySoundChannel != null) {
mySoundChannel.stop();
pos = 0;
isPlaying = false;
}
}
var rectangle:Rectangle = new Rectangle(0,0,100,0);
var dragging:Boolean = false;
volume_mc.mySlider_mc.addEventListener(MouseEvent.MOUSE_DOWN, startDragging);
function startDragging(event:Event):void {
volume_mc.mySlider_mc.startDrag(false,rectangle);
dragging = true;
volume_mc.mySlider_mc.addEventListener(Event.ENTER_FRAME, adjustVolume);
}
function adjustVolume(event:Event):void {
var myVol:Number = volume_mc.mySlider_mc.x / 100;
var mySoundTransform:SoundTransform = new SoundTransform(myVol);
if (mySoundChannel != null) {
mySoundChannel.soundTransform = mySoundTransform;
}
}
stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
function stopDragging(event:Event):void {
if (dragging) {
dragging = false;
volume_mc.mySlider_mc.stopDrag();
}
}
【问题讨论】:
标签: actionscript streaming mp3