What do I type to connect to my server
this sample code mp3 player works within flex. code both flash media server , streaming mp3 off regular server. cannot have media server because on shared server. when connecting server, instead of "rtmp" type connect server. underlined part of code talking below. assume "http://" not sure put after that. sorry if 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();
(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;
// 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);
// 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 {
(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>
More discussions in Flex (Read Only)
adobe
Comments
Post a Comment