• About
  • Blog News

  • Online Video
    • Trends
    • Showcase
    • Flash Video
    • HTML5 Video
    • Live Video
    • Media Servers
    • Streaming
    • Content Protection
  • Mobile
    • Trends
    • Adobe AIR
    • Showcase
    • Devices
    • Android
    • Apple
    • RIM
    • Digital Home
  • Interactive Web
    • Trends
    • Fun
    • Showcase
    • Gaming
    • 3D
    • HTML5
    • Flash/Flex
  • Advertisement
  • Articles
  • Events

Home » Mobile » Adobe AIR » Tune In to Live Radio with Adobe AIR

Tune In to Live Radio with Adobe AIR

Posted by: Jens Loeffler    Tags:  adobe air, live, Mobile    Posted date:  January 18, 2012  |  5 Comments



As mentioned in my previous post “The Ultimate Guide to Understanding Advanced Video Delivery with AIR for Mobile“, Adobe AIR can help to significantly reduce fragmentation on devices. Here is another example of an AIR use case that allows to drastically gain reach with minimal investment – live radio streaming.

RTMP is a widely deployed streaming protocol for radio stations. AIR allows to tap into the existing server infrastructure, and stream the content to devices. In this example we are focusing on AAC+ audio streaming to Android devices with RTMP. For other platforms and/or codecs, please refer to the codec/protocol look-up table.

Features relevant to radio live streaming

  • Broad device reach, independent from underlying streaming capabilities
  • Reduced latency e.g. for live events, news, etc.
  • Intelligent reconnect feature to ensure a continuous stream while switching networks
  • Advanced metadata for title, artist and album

As explained in the my previous summary, Adobe AIR addresses the first requirement – device fragmentation. Since AIR is supported on Android 2.2 and higher, RTMP with AAC+ works automatically on the majority of all Android devices without customization or device specific testing.

Radio on Galaxy SRTMP fulfills the second requirement, very low live latency. The protocol was originally designed for real-time 2-way video communication, therefore has very minimal delay. That said, for live on mobile a buffer is recommended for smooth playback, which is user defined and set to 5 seconds in this example. Of course it’s also possible to switch to an HTTP based delivery approach with HDS, which changes the latency characteristics and reconnect requirements.

Next on the list is the reconnect feature, which is specifically important for a protocol like RTMP that maintains a consistent connection. If the connection is lost, or switches between networks, the playback will less likely pause with this feature. The application will try to reconnect while the buffer plays out. If it connects quickly enough, no interruption of the live stream will occur. The reconnect feature is automatically enabled in the latest version of OSMF.

Last but not least, the advanced metadata for title, artist or album. Live metadata is embedded as part of the stream, which is a feature that has been supported for years. Advanced encoders like the audio optimized Orban encoders and others support live metadata.

For the best experience, the encoder should provide data of the current song as part of the metadata sent when subscribing to the stream, and live cuepoints to update the information during playback. Instead of the encoder, an intermediate server can provide this as well, but you can find more information in the live metadata article.

And finally, 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>

Conclusion

With a couple of lines of client code it is possible to create a basic, but highly functional, radio application, that allows the use existing work flows and reach millions of Android users without having to worry about fragmentation.

About the author
Jens Loeffler
Technology enthusiast and evangelist, with a passion for online video and mobile. Senior technical evangelist on Adobe's Media Solutions product management team focusing on online video and services. The views expressed on this blog are personal views.



Related Posts

GoDaddy.com Places Gigantic QR Code on NYC Times Squares – This Post Proves It Works
It's one of these things you should ignore, but size can make a difference, as this initiative demonstrates. GoDaddy.com placed a gigantic billboard on NYC's Times Square, and it at least got my attention. I personally...


Apache Flex – And It Begins With a New Logo
The recent months have been very eventful for Flex developers, and initial concerns turned quickly into excitement to get behind the new opportunity. Flex made significant recent steps to become a full open-source project,...


4 Power Tips to Increase Adobe AIR Mobile Performance
The featured image shows Machinarium, a blockbuster Adobe AIR iPad game currently in the iOS App Store. Even though I personally didn't have insight in their performance optimization, here are some generic quick tips to improve...


Sign in or Post as Guest
Livefyre logo
  • Comment help
  • Get Livefyre
Post comment as
twitter logo facebook logo
Sort: Newest | Oldest
slavomirdurej
slavomirdurej 5 pts

Is this app working ONLY on Android ?

I am testing on win 7 , Air 3.2 Flex SDK 2.6 and it keeps giving me the :

Exception fault: Error: The specified capability is not currently supported at org.osmf.media::MediaPlayer/getTraitOrThrow

error ?

share
  • spam
  • offensive
  • disagree
  • off topic
Like
Jens Loeffler
Jens Loeffler 5 pts moderator

You probably have an old version. Make sure to use the latest OSMF version (http://www.osmf.com), not the one build into Flex (remove the Flex OSMF.swc link and replace it with the latest).

share
  • spam
  • offensive
  • disagree
  • off topic
Like
slavomirdurej
slavomirdurej 5 pts

Jens Loeffler Hi, thank you for replay. That was the first thing I tried of course, removed the one from the Flex SDK and linked newest osmf swc (v1.6).. Didn't help unfortunately. This should work on windows as well right ? Do I need to have specific codec installed on the system ? What is a good free rtmp url to test this on ?

share
  • spam
  • offensive
  • disagree
  • off topic
Like
Jens Loeffler
Jens Loeffler 5 pts moderator

slavomirdurej It should work on windows as well, but it's important to replace my placeholder URL with a proper RTMP URL. Unfortunately I can't share my source stream, but it was encoded by Orban http://www.orban.com/products/streaming/opticodec-...

share
  • spam
  • offensive
  • disagree
  • off topic
Like

Trackbacks
  1. New Adobe Articles and videos – Adobe User Group - Philippines says:
    January 31, 2012 at 9:31 pm

    [...] Tune in to live radio with Adobe AIR http://www.flashstreamworks.com/2012/01/18/tune-in-to-live-radio-with-adobe-air/ [...]

  • Find Articles

  • Recent Posts

    • Nike's "Quick Controls Chaos" Pushes Interactive Web Video Forward
      I've always been fascinated by well produced video-based marketing sites, specifically...
    • Monolith - A Playful Agency Site with Stage3D
      Monolith, a Japanese ad agency, created their agency site with Stage3D (via Flash...
    • Is Samsung's Ad Strategy Oddly Similar to Apple's?
      I remember first seeing the Samsung Galaxy S II commercial  "The Way We're Wired"...
  • Popular Posts

    • HLS vs. HDS - What Is the Difference and Why You Should Care
      Unless you work daily in the streaming business, it's sometimes hard to get into...
    • The Ultimate Guide to Understanding Advanced Video Delivery with AIR for Mobile
      Adobe AIR provides a very attractive abstraction layer for video playback on mobile...
    • The 54th Grammy's Rock with Stage3D
      Literally. The new site "We are music" for the 54th Grammy's, airing on CBS on Sunday,...
  • News in Pictures

  • Social Media





 
  • Online Video

    • The Mystery Behind Live Streaming Delay
      One side effect of living in the year 2012 is that major events, such as the World...

    • Best Practices & Guidelines for In Stream Video Ads
      In Stream Video ads are some of the most popular type of ads for advertisers, agencies...

    • Mobile Video with PhoneGap, HTML5 and Strobe Media...
      PhoneGap is a powerful HTML5 based cross platform application platform, but how well...

    • Vote on the Next HTML5 Media Topic
      As indicated in the recent survey, 23% of you are interested in HTML5. And to help...

  • Mobile

    • Apache Flex - And It Begins With a New Logo
      The recent months have been very eventful for Flex developers, and initial concerns...

    • 4 Power Tips to Increase Adobe AIR Mobile Performance
      The featured image shows Machinarium, a blockbuster Adobe AIR iPad game currently...

    • Tune In to Live Radio with Adobe AIR
      As mentioned in my previous post "The Ultimate Guide to Understanding Advanced Video...

    • Source Code - 720p Video on iPad and Android Tablets...
      My guide to advanced video delivery with AIR for mobile resulted in a lot of interest,...

  • Interactive Web

    • Nike's "Quick Controls Chaos" Pushes Interactive Web Video...
      I've always been fascinated by well produced video-based marketing sites, specifically...

    • Monolith - A Playful Agency Site with Stage3D
      Monolith, a Japanese ad agency, created their agency site with Stage3D (via Flash...

    • MINI Fumbles With Their New Online Car Configurator
      MINI, which had amazing amazing marketing campaigns over the years, included a new car configurator on...

    • Angry Birds Is Not Huge, It's Massive
      It's often easy to underestimate the size of certain, highly recognized brands. Rovio,...

  • Contact Us

    CAPTCHA Image
    Refresh Image

 
The views expressed on this blog are personal views and should not be taken to represent corporate strategy or official Adobe positions.
The content of the posts at this site should not be re-distributed by commercial media.
(c) 2012 Flashstreamworks | Logo Design Stiehl/Over