The easiest way to play an audio RTMP stream in Android The easiest way to play an audio RTMP stream in Android android android

The easiest way to play an audio RTMP stream in Android


It is unfortunately non-trivially difficult to do. Right now your best bet is to look at the code in http://code.google.com/p/android-rtmp-client/: specifically look at http://code.google.com/p/android-rtmp-client/source/browse/trunk/example/com/ryong21/example/recorder/RecorderClient.java and http://code.google.com/p/android-rtmp-client/source/browse/trunk/example/com/ryong21/example/recorder/Recorder.java. These walk through taking in a streamed MP3 file and recording its contents to an FLV file on disk.

You would need to modify the RecorderClient.java file (specifically around line 193) to play the audio data out the speakers.


Not sure if this helps, but... I was able to do something similar (rtmp - streaming video) using Flash, so you need Android 2.2+ for this.

Anyway, I just wrote an HTML page displaying the flash video then opened the page in a WebView.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><style type="text/css" media="screen">    html, body{        margin:0;        padding:0;        height:100%;    }    #altContent{        width:100%;        height:100%;    }</style><title>YOUR TITLE HERE!</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script><script type="text/javascript">    var flashvars = {};    flashvars.HaloColor = "0x0086db";    flashvars.ToolTips = "true";    flashvars.AutoPlay = "true";    flashvars.VolumeLevel = "50";    flashvars.CaptionURL = "YOUR CAPTION HERE";    flashvars.Title = "YOUR TITLE HERE";    flashvars.Logo = "";    flashvars.SRC = "rtmp://YOUR STREAM URL HERE";    flashvars.BufferTime = "5";    flashvars.AutoHideControls = "false";    flashvars.IsLive = "true";    var params = {};    params.wmode = "transparent";    params.allowfullscreen = "true";    var attributes = {};    attributes.id = "L3MP";    swfobject.embedSWF("http://media-player.cdn.level3.net/flash/v1_1_1/Level3MediaPlayer.swf", "altContent", "100%", "100%", "10.1.0","http://media-player.cdn.level3.net/flash/v1_1_1/expressInstall.swf", flashvars, params, attributes);</script></head><body> <div id="altContent">   <center> <BR><BR><span style="color:red"><b>Please Install Adobe Flash Player</b>          </span><BR><BR>  <a href="http://www.adobe.com/go/getflashplayer"><img     src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a>  </center>      </div> </body></html></script></html>

OK... now just save that in your assets folder in your projectand open it with something like this in your activity :

    String LocalFile = "file:///android_asset/YOUR_HTML_FILE.htm";    WebView webView = (WebView) findViewById(R.id.YOUR_WEB_VIEW);    WebSettings webSettings = webView.getSettings();    webSettings.setJavaScriptEnabled(true);    webSettings.setPluginsEnabled(true);    webSettings.setLoadWithOverviewMode(true);    webSettings.setUseWideViewPort(true);     webSettings.setAllowFileAccess(true);    webView.setBackgroundColor(Color.BLACK);    webView.setVerticalScrollBarEnabled(false);    webView.setHorizontalScrollBarEnabled(false);    webView.loadUrl(LocalFile);

Its a bit of a work around... Hope it works for you. CDub.