0 Replies Latest reply on May 26, 2009 7:27 PM by lmcrun19

    What do I type to connect to my server

    lmcrun19

      This is sample code for a mp3 player that works within flex. The code is for both flash media server and for streaming a mp3 off a regular server. I cannot have a media server because I am on shared server. When connecting to my server, instead of the "rtmp" what would I type to connect to my server. I underlined the part of the code that I am talking about below. I assume its "http://" but I not sure what to put after that. Sorry if this is a newbie question.

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
          pageTitle="My Streaming Flex 2 MP3 Radio" xmlns:fx="com.fusiox.ui.*"
          initialize="initApp()" creationComplete="PageLoaded()" backgroundColor="#F4F4F4"
          themeColor="haloBlue" viewSourceURL="srcview/index.html" layout="vertical">
         
          <mx:HTTPService id="songService" url="http://www.logic.com/mp3player/assets/songList.xml" showBusyCursor="true" />
          <mx:Style>
              .heading{fontFamily:Arial;fontWeight:bold;color:#C73105;fontSize:12pt;}
              .logo{fontFamily:Arial;fontWeight:bold;color:navy;fontSize:10pt;}
              .mainTitle{fontFamily:Arial;fontWeight:normal;color:grey;fontSize:9pt;}
              .mainTitleBold{fontFamily:Arial;fontWeight:bold;color:navy;fontSize:11pt;}
          </mx:Style>
          <mx:Script>
              <![CDATA[
                  import mx.controls.Alert;
                  import flash.utils.Timer;
                  import flash.events.TimerEvent;           
                  import flash.media.Sound;
                  import flash.media.SoundLoaderContext;
                  import flash.media.SoundChannel;
                  import flash.media.SoundTransform;
                  import mx.core.SoundAsset;
                 
                 
                  [Bindable]
                  private var nc:NetConnection;
                  [Bindable]
                  private var isConnected:Boolean = false;
                  [Bindable]
                  private var mp3Song:String = "";
                  [Embed(source="images/pause.gif")]
                  [Bindable]
                  private var imgPauseClass:Class;
                  [Embed(source="images/play.gif")]
                  [Bindable]
                  private var imgPlayClass:Class;
                  [Embed(source="images/stop.gif")]
                  [Bindable]
                  private var imgStopClass:Class;
                  [Embed(source="images/dimpause.gif")]
                  [Bindable]
                  private var imgDimPauseClass:Class;
                  [Embed(source="images/dimplay.gif")]
                  [Bindable]
                  private var imgDimPlayClass:Class;
                  [Embed(source="images/dimstop.gif")]
                  [Bindable]
                  private var imgDimStopClass:Class;
                  /*
                  [Bindable]
                  private var sndTransform:SoundTransform = new SoundTransform();
                  */
                 
                  private var mp3Stream:NetStream;
                  private var id3Stream:NetStream;
                  private var dp:Array;
                  private var blnLoadDelayRunOnce:Boolean = false;
                  private var oNetStreamClient:Object = new Object();
                 
                  private var songURLReq:URLRequest;
                  private var channel:SoundChannel;

       

                  private function initApp():void {
                      songService.send();
                      nc = new NetConnection();
                      nc.objectEncoding = flash.net.ObjectEncoding.AMF0;
                   }

       

                  private function createConnection():void {
                      if(!nc.connected) {
                          nc.connect("rtmp://webmxml.no-ip.info/music");
                          nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
                      } else {
                          nc.close();
                          isConnected = false;
                      }
                  }

       

                  private function netStatusHandler(event:NetStatusEvent):void {
                      switch(event.info.code) {
                          case "NetConnection.Connect.Success":
                              connectionSuccess(new Event("success"));
                              btnPlay.enabled = true;
                          break;
                          case "NetConnection.Connect.Failed":
                              connectionFailed(new Event("failed"));
                          break;
                          default:
                              Alert.show("netStatusHandler:code: " + event.info.code);
                          break;
                      }
                  }
                 
                  private function connectionSuccess(event:Event):void {
                      isConnected = true;
                  }

       

                  private function connectionFailed(event:Event):void {
                      isConnected = false;               
                  }

       

                  private function readytoContinue():void {
                      if (songService.lastResult.song!=undefined) {
                          //mx.controls.Alert.show("number of songs: " + songService.lastResult.song.length);
                          var aryTemp:Array = new Array();
                          for (var i:Number=0; i<songService.lastResult.song.length; i++) {
                              aryTemp.push({value: songService.lastResult.song[i].name, label: songService.lastResult.song[i].name, data: songService.lastResult.song[i]});
                          }
                          dp = aryTemp;
                          cbxMusic.dataProvider = dp;               
                      }
                      blnLoadDelayRunOnce = true;
                  }
                 
                  private function PageLoaded():void {
                      var myTimer:Timer = new Timer(1000, 0);
                      myTimer.addEventListener("timer", onTimer);
                      myTimer.start();
                  }

       

                  private function onTimer(event:TimerEvent):void {
                      if (!blnLoadDelayRunOnce) {
                          readytoContinue();
                      }
                  }
                 
                  private function onSongClick(selItm:String):void {
                      frmID3.visible = false;
                      frmID3.height = 0;
                      mp3Song = selItm;
                      if (!isConnected) {
                          createConnection();
                      }
                      /*
                      var request:URLRequest = new URLRequest("http://webmxml.no-ip.info/mmug/technology/flash/songs/" + selItm + ".mp3");
                      var loader:URLLoader = new URLLoader(request);
                      songURLReq = request;
                      vis.visible = false;
                      vis.setStyle('audioLineColor',16737792)
                      vis.setStyle('audioFillColor',16776960)
                      loader.addEventListener(Event.COMPLETE, completeProgress);
                      */
                     }

                   public function onPlayEvent(sAction:String):void {
                      if (sAction=='play') {
                          btnPlay.enabled = false;
                          btnStop.enabled = true;
                          btnPause.enabled = true;
                          // for the playback
                          if (mp3Stream==null) {
                              mp3Stream = new NetStream(nc);
                          }
                          mp3Stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, catchAll);
                          mp3Stream.addEventListener(IOErrorEvent.IO_ERROR, catchAll);
                          mp3Stream.addEventListener(NetStatusEvent.NET_STATUS, catchAll);
                          mp3Stream.play("mp3:" + mp3Song);
                          // for the id3
                          if (id3Stream==null) {
                              id3Stream = new NetStream(nc);
                          }
                          id3Stream.client = this;
                          id3Stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, catchAll);
                          id3Stream.play("id3:" + mp3Song);
                      }
                  }

       

                  private function stopSound():void {
                      if (btnPlay.enabled==false) {
                          mp3Stream.pause();               
                          mp3Stream.play(false);
                          btnStop.enabled = false;
                          btnPause.enabled = false;
                          btnPlay.enabled = true;
                             //vis.visible = false;
                      }
                  }

       

                  private function pauseSound():void {
                       if (btnPause.label=="Pause") {
                           btnPause.label = "Resume"
                       } else {
                           btnPause.label = "Pause"
                       }
                       mp3Stream.togglePause();
                  }

       

                  private function catchAll(event:Object):void {
                      if (event.type == "netStatus") {
                          trace("catchAll:code:" + event.info.code);
                      } else {
                          trace("catchAll:event:" + event);
                      }
                  }

       

                  public function onId3(event:Object):void {
                      for (var b:String in event) {
                          if (event[b]!=undefined) {
                              this["lbl_" + b].text = event[b];
                           }
                      }
                      if (lbl_genre.text!='' || lbl_artist.text!='' || lbl_songtitle.text!='' || lbl_track.text!='' || lbl_album.text!='' || lbl_year.text!='' || lbl_comment.text!='') {
                          frmID3.visible = true;
                          frmID3.height = 200;
                      }
                  }  

       

                     /*
                     private function completeProgress(event:Event):void {
                         sndTransform.volume = 0
                         var mySound:Sound = new Sound(songURLReq, new SoundLoaderContext(1000, true));
                         channel = mySound.play(0,1);
                      channel.soundTransform = sndTransform;
                         vis.visible = true;
                     }
                     */

       

               ]]>
          </mx:Script>
          <mx:Panel id="pnlMP3" title="My Streaming Flex 2 MP3 Radio" styleName="heading" backgroundColor="#F4F4F4" paddingLeft="4" paddingTop="4" width="312" height="89" cornerRadius="0" headerHeight="18">
              <mx:ComboBox id="cbxMusic" change="onSongClick(cbxMusic.selectedItem.value)" styleName="logo" width="283"/>
              <mx:HBox>
                  <mx:Button id="btnPlay" label="Play" labelPlacement="left" icon="{(btnPlay.enabled)?imgPlayClass:imgDimPlayClass}" click="onPlayEvent('play')" styleName="{(btnPlay.enabled)?'mainTitleBold':'mainTitle'}" enabled="false" toolTip="Play" />
                  <mx:Button id="btnPause" label="Pause" labelPlacement="left" icon="{(btnPause.enabled)?imgPauseClass:imgDimPauseClass}" click="pauseSound()" styleName="{(btnPause.enabled)?'mainTitleBold':'mainTitle'}" enabled="false" toolTip="{(btnPause.label=='Pause')?'Pause':'Resume'}" />
                  <mx:Button id="btnStop" label="Stop" labelPlacement="left" icon="{(btnStop.enabled)?imgStopClass:imgDimStopClass}" click="stopSound()" styleName="{(btnStop.enabled)?'mainTitleBold':'mainTitle'}" enabled="false" toolTip="Stop" />
                  <mx:Label id="lblLoading" text="Loading..." styleName="mainTitle" height="24" visible="false" />
              </mx:HBox>
          </mx:Panel>
          <mx:Form id="frmID3" visible="false" height="0" width="100%" paddingLeft="{pnlMP3.x - 20}">
              <mx:FormItem label="Genre">
                  <mx:Label id="lbl_genre" width="200"/>
              </mx:FormItem>   
              <mx:FormItem label="Artist">
                  <mx:Label id="lbl_artist" width="200"/>
              </mx:FormItem>   
              <mx:FormItem label="Title">
                  <mx:Label id="lbl_songtitle" width="200"/>
              </mx:FormItem>               
              <mx:FormItem label="Track">
                  <mx:Label id="lbl_track" width="200"/>
              </mx:FormItem>               
              <mx:FormItem label="Album">
                  <mx:Label id="lbl_album" width="200"/>
              </mx:FormItem>               
              <mx:FormItem label="Year">
                  <mx:Label id="lbl_year" width="40"/>
              </mx:FormItem>               
              <mx:FormItem label="Comment">
                  <mx:Label id="lbl_comment" width="200"/>   
              </mx:FormItem>
          </mx:Form>
          <!--<fx:Visualization id="vis" width="{pnlMP3.width}" height="400" visible="false" />-->
      </mx:WindowedApplication>