我目前正在尝试编写一个能够从多个来源流式传输的应用程序,我将把它作为一个列表。我希望用户单击列表中的一个选项,然后单击“播放”按钮,然后开始流式传输。我的代码现在正在运行,但是我已经明确说明了我想要播放的流,我还没有找到一种方法来动态地将 url 传递给 req new URL 请求。代码如下>
<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Stream Southeast Ak Stations" destructionPolicy="never">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<fx:Script
>
<![CDATA[
private var req:URLRequest;
private var context:SoundLoaderContext = new SoundLoaderContext(8000);
private var s:Sound;
private var channel:SoundChannel = new SoundChannel();
private var playingBln = new Boolean
private function playAudio():void
{
if (playingBln == true)
{playingBln = false;
channel.stop();
s.close()
req = new URLRequest('http://stream.ktoo.org:8000/ktoo');
s = new Sound(req, context);
channel = s.play();
playingBln = true
}
else{
req = new URLRequest('http://stream.ktoo.org:8000/ktoo');
s = new Sound(req, context);
channel = s.play();
playingBln = true
}
}
private function stopAudio():void
{
if (playingBln == true)
channel.stop();
s.close()
playingBln = false;
}
]]>
</fx:Script>
<s:Label text="Choose a Station"/>
<s:List id="stationList"
width="100%"
height="100%"
labelField="name"
>
<s:ArrayCollection>
<fx:Object name="KTOO" location="Juneau" streamURL="http://stream.ktoo.org:800/ktoo"/>
<fx:Object name="KXLL" location="Juneau" streamURL="http://stream.ktoo.org:800/kxll"/>
<fx:Object name="KRNN" location="Juneau" streamURL="http://stream.ktoo.org:800/krnn"/>
<fx:Object name="KFSK" location="Petersburg" streamURL="null"/>
<fx:Object name="KSTK" location="Wrangell" streamURL="null"/>
<fx:Object name="KCAW" location="Sitka" streamURL="null"/>
<fx:Object name="KRBD" location="Ketchikan" streamURL="null"/>
</s:ArrayCollection>
</s:List>
<s:Button x="10" y="309" width="100" height="42" label="Play" click="playAudio()"/>
<s:Button x="139" y="310" width="99" label="Stop" click="stopAudio()"/>
</s:View>