View Single Post
Old 3rd October 2012, 18:27   #127
Smelter
Major Dude
 
Smelter's Avatar
 
Join Date: Jan 2004
Posts: 1,141
F.A.Q. : " How the hell do I get the title data? I set up a policy file server but now what?"


code:

package
{
import com.thebitstream.flv.CodecFactory;
import com.thebitstream.flv.codec.AAC;
import com.thebitstream.flv.codec.AACP;
import com.thebitstream.flv.codec.MP3;
import com.thebitstream.flv.codec.MetaData;
import com.thebitstream.nsv.Shoutcast;
import com.thebitstream.provider.StreamEvent;

import flash.display.Sprite;
import flash.events.ContextMenuEvent;
import flash.events.Event;
import flash.external.ExternalInterface;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.ui.ContextMenu;
import flash.ui.ContextMenuItem;


CodecFactory.ImportCodec(MetaData);
CodecFactory.ImportCodec(AAC);
CodecFactory.ImportCodec(AACP);
CodecFactory.ImportCodec(MP3);

[SWF(width="320", height="125")]

public class RadioCafe extends Sprite
{
private var shoutcast:Shoutcast;
private var _title:String = "";
private var titleText:TextField = new TextField();

public function RadioCafe()
{
super();
addChild(titleText);
titleText.width=320;

titleText.text="Radio Cafe";
boot();
}

private function onCLickMenu(cme:ContextMenuEvent):void
{
flash.net.navigateToURL(new URLRequest("http://code.google.com/p/comserver/"),"_info");
}
private function boot():void
{

shoutcast=new Shoutcast();
shoutcast.addEventListener(StreamEvent.STATUS_CHANGED, onStreamEvent);
shoutcast.addEventListener(StreamEvent.CUEPOINT, onStreamEvent);
shoutcast.addEventListener(StreamEvent.METADATA_CHANGED, onStreamEvent);
shoutcast.addEventListener(StreamEvent.CONTENT_CHANGED, onStreamEvent);
shoutcast.volume= 1;
shoutcast.initStream(
XML("<item> "+
"<policy>xmlsocket://yourdomainOrIp</policy> "+
"<host>yourdomainOrIp</host>"+
"<connection>socket</connection>"+//socket allows title data
"<port>8064</port>"+
"<uri>/;stream.nsv</uri>"+
"</item>"));


contextMenu=new ContextMenu();
contextMenu.hideBuiltInItems();
var context:ContextMenuItem=new ContextMenuItem("AACplus by Thunder Snow");
context.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,onCLickMenu);
contextMenu.customItems=[context];
}


protected function onStreamEvent(event:StreamEvent):void
{
trace(event.type);
switch(event.type)
{
case StreamEvent.METADATA_CHANGED:
onMetaData(event.data);
break;

}

}

public function onMetaData(obj:Object):void
{
for(var prop:String in obj)
{
//trace(prop,":",obj[prop]);
if(prop=="StreamTitle" && obj[prop] && obj[prop].length)
{


var s2:String =obj[prop].toString();
var out:String="";


for(var i:int=0; i<s2.length; i++)
{
if(s2.charAt(i)=="%")
{

var val:uint=new uint( String( "0x"+s2.charAt(++i)+ s2.charAt(++i)));

out = out+ String.fromCharCode(val);

}
else
{

out = out+ s2.charAt(i);
}
}

var t:String=decode(obj[prop].toString());
this._title=t;
trace("title : "+ _title);
titleText.text=_title;



}
}
}

public function decode(s2:String):String
{

var out:String="";
for(var i:int=0; i<s2.length; i++){
if(s2.charAt(i)=="%"){

var val:uint=new uint( String( "0x"+s2.charAt(++i)+ s2.charAt(++i)));

out = out+ String.fromCharCode(val);

}else{

out = out+ s2.charAt(i);
}
}
return out;

}

public function get title():String
{
return _title;
}

}
}



Smelter is offline   Reply With Quote