12

Is there any 3rd-party library in Android or Java that can play radio live stream?

File extension: .asx
MIME type: video/x-ms-asf

Unfortunately, MediaPlayer does not support this format!

Here is the url of the live stream: http:// 38.96.148.75 /SunnahAudio


EDIT:

I was able to convert .asf file to .mp3 file by using JAVE:

File source = new File("sound.asf");
File target = new File("target.mp3");
AudioAttributes audio = new AudioAttributes();
audio.setCodec("libmp3lame");
audio.setBitRate(new Integer(64000));
audio.setChannels(new Integer(1));
audio.setSamplingRate(new Integer(22050));
EncodingAttributes attrs = new EncodingAttributes();
attrs.setFormat("mp3");
attrs.setAudioAttributes(audio);
Encoder encoder = new Encoder();
encoder.encode(source, target, attrs);

However, I'm streaming the .asf online and I am not sure if I could stream the radio station, convert it to .mp3, and immediately play it!


EDIT2:

I offer 500+ rep for anyone provides a full and working solution to play .asf live stream on Android. Basically, I want to play this radio station on Android (as xiialive can do):

http://38.96.148.75/SunnahAudio
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
  • I found an app on Google Play which can play .asf: [`xiialive`](https://play.google.com/store/apps/details?id=com.android.DroidLiveLite&feature=search_result#?t=W251bGwsMSwxLDEsImNvbS5hbmRyb2lkLkRyb2lkTGl2ZUxpdGUiXQ..), but I still need to play it on my own app. – Eng.Fouad Jul 20 '12 at 23:37
  • You are likely to need to use the Android NDK to build C libraries (from vlc, for example) that support streaming, then include them in your app. – Craig Ringer Jul 24 '12 at 01:33

2 Answers2

6

If you open url of the stream in VLC player you can find out that it is an MMS stream using WMA codec mmsh://38.96.148.75/SunnahAudio?MSWMExt=.asf Here is an open source project aacplayer-android which uses libmms and libffmpeg to get WMA content from mms:// stream and play it.
I hope it solves your problem.

vasart
  • 6,692
  • 38
  • 39
  • +1 thanks for extracting the mmsh link. I have tried that library and I always got errors such as `UnsatisfiedUinkError`, since I'm not familiar with Android NDK. – Eng.Fouad Jul 23 '12 at 00:09
5

I was able to successfully play your stream on Android using Vitamio library. The biggest advantage of this lib is that it's API-compatible with Android SDK, so you'll just have to change imports in your code.

One of Vitamino plugins should be present on given device to use the library. Simply open Vitamio Demo in Eclipse and take a look at how to use it. Prompting user to install Vitamio plugin is included in demo.

I was able to play your stream with this code:

import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
import android.app.Activity;
import android.os.Bundle;

public class VideoViewDemo extends Activity {

    private String path = "mmsh://38.96.148.75/SunnahAudio";
    private VideoView mVideoView;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.videoview);
        mVideoView = (VideoView) findViewById(R.id.surface_view);
        mVideoView.setVideoPath(path);
        mVideoView.setMediaController(new MediaController(this));
        mVideoView.requestFocus();
    }

}

As you can see - similar to using VideoView from Android SDK. Pretty much the only difference are imports.

The only difference to be noted is that I was unable to use http link, so I had to use the real streaming URL with mmsh protocol (opened in VLC - similar to what @vasart did).

For reference you can take a look at logs from successful playback.

vArDo
  • 4,408
  • 1
  • 17
  • 26
  • +1 Thank you for your response. I don't want the users of my app to install any extra apps, what I need is to include it within my app :) – Eng.Fouad Jul 23 '12 at 00:12
  • @Eng.Fouad Installing external Vitamio app/plugin was the fastest way to check if Vitamio will play it out, but as far as I remember it is not the only one. Unfortunately, it seems that Vitamio site is down, so I can't give you direct reference right now. – vArDo Jul 23 '12 at 07:44
  • The desktop version website is down, however, mobile version website is still available at [here](http://m.vov.io/). – yorkw Jul 23 '12 at 23:34
  • @yorkw Unfortunately the mobile site does not describe alternative ways to install/include Vitamio plugin, so that user doesn't have to make any actions. I've written to them that the site is down but without any response. – vArDo Jul 25 '12 at 06:35
  • The alternative way you talking about is **Vitamio-SDK.7z**, it is simply a jar file that you can include and use in your own application. Just google Vitamio-SDK.7z, I am sure there should be other place where you can download it. – yorkw Jul 25 '12 at 08:32
  • @yorkw The problem with the jar file, you've mentioned, is that it weights about 60KB, so there's no way that it includes all encoders and decoders. So, the tricky part is how to get all the *ffmpeg* (which is used by *Vitamio*) goodies working on Android without forcing user to install *Vitamio plugin* manually. – vArDo Jul 25 '12 at 09:38