Warm tip: This article is reproduced from serverfault.com, please click

Developing A Streaming Server For Android

发布于 2011-04-05 22:48:09

I am trying to develop a Streaming AV Media Server for use with an Android handset as the client. This instantly puts a constraint on me to develop a server that uses RTSP. I am versed in Java programming and have found that Netty (Java NIO) can be used to fill in the otherwise massive gap in the Java Media Framework for this protocol. I have played around with it and have had no real success. I know about live555 but I’m on a tight schedule and don't really want to start messing around with C++ as I know very little on the subject. I have been stuck on this problem for many weeks and have nothing really to show for it. Streaming to android must be possible as there are numerous proprietary apps on the Android market. Could someone who has experience and knowledge on this subject please let me know if there is a simple way to implement an RTSP AV media server that just streams .mp4 or .3gp and .mp3 for use with android without using the live555 libraries. If not I will just have to quickly get up to speed on C++. Thank you in advance.

Questioner
user673090
Viewed
11
Squonk 2011-04-06 08:43:26

OK, simple as this to stream using HTTP.

I created a virtual folder called 'Music' with IIS on WinXP and pointed it at a folder containing mp3 files. This is the complete Activity needed to stream a file (name hard-coded).

BTW, it's called SimpleNetRadio as I originally started playing around with Shoutcast streams.

package com.mycompany.SimpleNetRadio;

import android.app.Activity;
import android.media.AsyncPlayer;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Bundle;

public class SimpleNetRadio extends Activity
{
    private AsyncPlayer ap = null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }

    @Override
    protected void onStart() {
        super.onStart();
        ap = (AsyncPlayer) getLastNonConfigurationInstance();
    }

    @Override
    protected void onStop() {
        super.onStop();
        if (ap != null)
            ap.stop();
    }

    @Override
    protected void onResume() {
        super.onResume();

        if (ap == null) {
            ap = new AsyncPlayer("Simple Player");
            ap.play(this, Uri.parse("http://192.168.1.1/Music/02%20-%20Don't%20Stop%20Believin'.mp3"), true, AudioManager.STREAM_MUSIC);
        }
    }

    @Override
    public Object onRetainNonConfigurationInstance() {
        return ap;
    }
}

You should also be able to do this with MediaPlayer with a bit more code - it would handle error conditions better and wouldn't require much more work.