2013-05-12 59 views
0

我目前正在嘗試編寫一個應用程序,該應用程序可以從多個來源進行流式傳輸,我將以列表形式提供這些應用程序。我希望用戶點擊列表中的選項,然後點擊「播放」按鈕,並開始流式傳輸。我的代碼現在正在工作,但我已明確聲明瞭我想播放的流,但我還沒有找到一種方法將url動態傳遞到req新的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> 

回答

0

使用stationList.selectedItem,SOR的是這樣的:

private function playAudio():void 
    { 
     if (playingBln == true) 
     {playingBln = false; 
      channel.stop(); 
      s.close() 
     } 
     var streamURL :String = stationList.selectedItem.streamURL; 
     req = new URLRequest(streamURL); 
     s = new Sound(req, context); 
     channel = s.play(); 
     playingBln = true 
    } 

我還調整了你的算法,所以你沒有相同的代碼兩個獨立的部分。