Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 4    Views: 167

buzzbt
Android Fan
Profile
Posts: 233
Reg: Nov 14, 2011
las vegas
6,530
09/12/12 08:56 PM (13 years ago)

Live Radio with Adobe AIR ? how can we use this code ?

HI ALL! i was googling around to see if i fund live radio (RTMP) player for android project this seems interesting but i couldn't make it to work can any one help what to do to make it work. many thanks! http://www.overdigital.com/2012/01/18/tune-in-to-live-radio-with-adobe-air/ the complete code <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" backgroundColor="#000000" applicationDPI="160" creationComplete="init()"> <fx:Script> <![CDATA[ import mx.core.UIComponent; import org.osmf.containers.MediaContainer; import org.osmf.elements.AudioElement; import org.osmf.events.MediaElementEvent; import org.osmf.events.MediaPlayerStateChangeEvent; import org.osmf.events.TimelineMetadataEvent; import org.osmf.media.MediaElement; import org.osmf.media.MediaPlayer; import org.osmf.media.MediaPlayerState; import org.osmf.metadata.CuePoint; import org.osmf.metadata.TimelineMetadata; import org.osmf.net.NetClient; import org.osmf.net.StreamType; import org.osmf.net.StreamingURLResource; import org.osmf.traits.LoadTrait; import org.osmf.traits.MediaTraitType; private var container:MediaContainer; private var background:Sprite; private var mediaPlayer:MediaPlayer; private var audioElement:MediaElement; private var bufferTimer:Timer; private function init() : void { // OSMF MediaContainer container = new MediaContainer(); var containerui:UIComponent = new UIComponent(); containerui.addChild(container); addElement(containerui); // Source var resource:StreamingURLResource = new StreamingURLResource("rtmp://myserver.com/live/mystream",StreamType.LIVE); audioElement = new AudioElement(resource); container.addMediaElement(audioElement); // OSMF MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.media = audioElement; mediaPlayer.autoPlay = false; //Define the buffer time mediaPlayer.bufferTime = 5; //Timer to display the buffer bufferTimer = new Timer(200); bufferTimer.addEventListener(TimerEvent.TIMER,bufferUpdate) bufferTimer.start(); // Metadata events audioElement.addEventListener(MediaElementEvent.METADATA_ADD, onMetadataAdd); mediaPlayer.addEventListener(MediaPlayerStateChangeEvent.MEDIA_PLAYER_STATE_CHANGE, onMediaStateChange); } // Add the metadata event handler for the first time metadata when subscribing to the live stream protected function onMediaStateChange(e:MediaPlayerStateChangeEvent): void { switch(e.state) { case MediaPlayerState.READY: var loadTrait:LoadTrait = mediaPlayer.media.getTrait(MediaTraitType.LOAD) as LoadTrait; var netStream:NetStream = loadTrait["netStream"] as NetStream; var netConn:NetConnection = loadTrait["connection"] as NetConnection; NetClient(netStream.client).addHandler("onMetaData", onMetaDataHandler); break; } } protected function onMetaDataHandler(info:Object):void { //Parse the stream metadata information and assign to UI } // Monitor the live cuepoints during playback for updated metadata information private function onMetadataAdd(event:MediaElementEvent):void { if (event.namespaceURL == CuePoint.EMBEDDED_CUEPOINTS_NAMESPACE) { var timelineMetadata:TimelineMetadata = audioElement.getMetadata(CuePoint.EMBEDDED_CUEPOINTS_NAMESPACE) as TimelineMetadata; timelineMetadata.addEventListener(TimelineMetadataEvent.MARKER_TIME_REACHED, onCuePoint); } } private function onCuePoint(event:TimelineMetadataEvent):void { //Parse the stream metadata information and assign to UI } // Display the updated buffer private function bufferUpdate(e:TimerEvent) : void { buffer_txt.text = (Math.floor(mediaPlayer.bufferLength*100)/100).toString(); } // Play and pause buttons private function togglePlayback() : void { if (mediaPlayer.playing) { mediaPlayer.stop(); playbutton.label = "Start Playback"; } else { mediaPlayer.play(); playbutton.label = "Stop Playback"; } } ]]> </fx:Script> <s:VGroup x="0" y="0" width="100%" height="100%"> <s:Label id="buffer_txt" width="30%" height="5%" fontSize="20" text="Buffer" color="#FFFFFF"/> <s:Scroller id="contentScroller" height="75%" width="100%"> <s:Group> <s:Image id="coverimg" x="10" y="130" width="300" height="202"/> <s:Label id="title_txt" x="12" y="70" width="300" height="31" color="#BBBBBB"/> </s:Group> </s:Scroller> <s:Button id="playbutton" width="100%" height="20%" label="Start Playback" click="togglePlayback()" fontSize="20" /> </s:VGroup> </s:Application>
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
09/13/12 03:40 AM (13 years ago)
Are you using the adobe flex sdk and osm framework?
 
buzzbt
Android Fan
Profile
Posts: 233
Reg: Nov 14, 2011
las vegas
6,530
like
09/13/12 04:36 AM (13 years ago)
Thank you raveyd! no i am not using adobe flex sdk and osm framework. i was looking rtmp streamer JW Player works but wane i embed it in Custom html The back button on the app doesn't controls the player When viewing a web page on a Custom URL/web page the website/page is 'encapsulated' inside that app page & therefore If you open HTML pages & stream video or audio when tapping the back button in the navigation bar the video or audio doesn't stop playing. Vers 1:4 The only way to stop playing is tap on stop button inside HTML before you tapping the back button or if you need to close them you have to go back to home screen menu and click menu on your phone and choose terminate . I tout if I use Vers 2:0 will solve the problem 2:0 no way to stop it ether you have to restart the phone. it Is impossible wane I tap the back button on the app to lose the pages to make it lose. Thanks!
 
Paul Rogers
Android Fan
Profile
Posts: 2524
Reg: May 30, 2011
UK
35,740
like
09/13/12 05:55 AM (13 years ago)
haha! gotta love google and bt! http://www.buzztouch.com/forum/thread.php?tid=253B557642580CEB3681EB7 Looks like David offers some solutions. Take him up on the offer to view the html!
 
buzzbt
Android Fan
Profile
Posts: 233
Reg: Nov 14, 2011
las vegas
6,530
like
09/13/12 06:16 AM (13 years ago)
Kikiki...you got me Looks like I miss Davids offers for solutions. Thanks !
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.